】。"/> 】。">

首頁  >  文章  >  web前端  >  vue.js如何遍歷map

vue.js如何遍歷map

coldplay.xixi
coldplay.xixi原創
2020-11-10 15:42:507827瀏覽

vue.js遍歷map的方法:vue使用【v-for】遍歷Map,程式碼為【6fab9fed0ee924d0559946d206b7b31f】。

vue.js如何遍歷map

本教學操作環境:windows10系統、vue2.9,本文適用於所有品牌的電腦。

【相關文章推薦:vue.js

#vue.js遍歷map的方法:

物件資料如下:

"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>

關鍵就是v-for="(item, key) of cities",相當於Map結構的(key, 值)

相關免費學習推薦:JavaScript(影片)

以上是vue.js如何遍歷map的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn