猿问

关于vuejs的v-for循环问题

vue.js要如何做到类似for in的方法遍历对象,我要取到对象内的某个字段名和值。

慕桂英4014372
浏览 479回答 1
1回答

慕婉清6462132

<div id="box">&nbsp; &nbsp; <ul>&nbsp; &nbsp; &nbsp; &nbsp; <li v-for="val in arr" track-by="$index">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {{val}}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </li>&nbsp; &nbsp; </ul></div>var vm=new Vue({&nbsp; &nbsp; el:'#box',&nbsp; &nbsp; data:{&nbsp; &nbsp; &nbsp; &nbsp;arr:['apple','banana','orange']&nbsp; &nbsp; },&nbsp; &nbsp; methods:{&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }});对于arr里面的$index 和 $key&nbsp; 在1.0之内的版本可以使用,在2.0之后就摒弃了,引入框架版本的时候一定要注意,在2.0还可以用&nbsp; v-for="(val,index) in arr"&nbsp; &nbsp;{{index}}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答