element icon indicating copy to clipboard operation
element copied to clipboard

如何使用v-for 动态生成Menu-Item 的index?

Open tandajun opened this issue 10 years ago • 5 comments

如题

tandajun avatar Oct 28 '16 03:10 tandajun

这个应该是vue的相关问题吧……

你可以使用v-for的index参数,参考v-for的用法:http://vuejs.org/guide/list.html#Basic-Usage

当然也可以自行在数据中提供唯一的key作为index

jikkai avatar Oct 28 '16 08:10 jikkai

我知道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属性

tandajun avatar Oct 31 '16 00:10 tandajun

@AppHL <el-menu-item :index="index"> 参考vue的绑定语法:http://vuejs.org/guide/syntax.html#Attributes

jikkai avatar Oct 31 '16 00:10 jikkai

请参考楼上的回答。另外,感觉你应该把 v-for 写在 el-menu-item 标签里,而不是 el-menu 标签里。

Leopoldthecoder avatar Oct 31 '16 00:10 Leopoldthecoder

哦 是的 谢谢!

tandajun avatar Oct 31 '16 00:10 tandajun