如何使用v-for 动态生成Menu-Item 的index?
如题
这个应该是vue的相关问题吧……
你可以使用v-for的index参数,参考v-for的用法:http://vuejs.org/guide/list.html#Basic-Usage
当然也可以自行在数据中提供唯一的key作为index
我知道v-for的index用法,之前的提问的代码没有显示出来,请看如下代码:
<el-menu default-active="0" v-for="(item, index) in items"> <el-menu-item index="index"></el-menu-item><el-menu-item index="{{ index }}"></el-menu-item> </el-menu>
在这里循环中的index的值不能注入index属性
@AppHL
<el-menu-item :index="index">
参考vue的绑定语法:http://vuejs.org/guide/syntax.html#Attributes
请参考楼上的回答。另外,感觉你应该把 v-for 写在 el-menu-item 标签里,而不是 el-menu 标签里。
哦 是的 谢谢!