溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

vue.js遍歷map的方法

發(fā)布時(shí)間:2020-12-09 13:59:59 來源:億速云 閱讀:1258 作者:小新 欄目:編程語言

這篇文章主要介紹了vue.js遍歷map的方法,具有一定借鑒價(jià)值,需要的朋友可以參考下。希望大家閱讀完這篇文章后大有收獲。下面讓小編帶著大家一起了解一下。

vue.js遍歷map的方法:vue使用【v-for】遍歷Map,代碼為【<div class="area" v-for="(item, key) of cities" :key="key">】。

vue.js遍歷map的方法:

對(duì)象數(shù)據(jù)如下:

"cities": {
"A": [{
"id": 56,
"spell": "aba",
"name": "阿壩"
}, {
"id": 57,
"spell": "akesu",
"name": "阿克蘇"
}],
"B": [{
"id": 58,
"spell": "baiyin",
"name": "白銀"
}, {
"id": 59,
"spell": "bangbu",
"name": "蚌埠"
}],
"C": [{
"id": 60,
"spell": "chengdu",
"name": "成都"
}, {
"id": 61,
"spell": "cangzhou",
"name": "滄州"
}]

遍歷方法如下:

<div class="area" v-for="(item, key) of cities" :key="key">
                <div class="title border-topbottom">{{key}}</div>
                <div class="item-list">
                    <div class="item border-bottom" v-for="innerItem of item" :key="innerItem.id">{{innerItem.name}}</div>
                </div>
            </div>

關(guān)鍵就是 v-for="(item, key) of cities",相當(dāng)于Map結(jié)構(gòu)的 (key, value)

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享vue.js遍歷map的方法內(nèi)容對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,遇到問題就找億速云,詳細(xì)的解決方法等著你來學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI