亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - Question about v-for loop in vuejs
習(xí)慣沉默
習(xí)慣沉默 2017-07-05 10:43:22
0
6
973

How do vue.js traverse objects using a for in-like method? I want to get a certain field name and value in the object.

習(xí)慣沉默
習(xí)慣沉默

reply all(6)
小葫蘆
<p id="box">
    <ul>
        <li v-for="val in arr" track-by="$index">
            {{val}}
           
        </li>
    </ul>
</p>

var vm=new Vue({
    el:'#box',
    data:{
       arr:['apple','banana','orange']
    },
    methods:{
        
    }
});
對(duì)于arr里面的$index 和 $key  在1.0之內(nèi)的版本可以使用,在2.0之后就摒棄了,引入框架版本的時(shí)候一定要注意,在2.0還可以用  v-for="(val,index) in arr"   {{index}}
僅有的幸福

Don’t quite understand what it means?

Do you want to use v-for to display it on the page?

Or is it?

我想大聲告訴你

Object.keys obtains the array composed of the keys of this object, v-for traverses the array, and obtains the fields in the form of obj[k]

大家講道理
<p id="box">
    <ul>
        <li v-for="(val,key) in arr" track-by="$index">
            {{key}}:{{val}}  //key是鍵,val是值           
        </li>
    </ul>
</p>

var vm=new Vue({
    el:'#box',
    data:{
       arr:['apple','banana','orange']
    }
});
洪濤

v-for = ‘(item, index) in items’
items array
item array item
index array item corresponding subscript
Code must be wrapped in quotes

ringa_lee
<p v-for="(val, key) in object"></p>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template