<div v-for="(item, index) in cMList" :key=index>
……
…… <div v-for="(items, indexs) in item.list" :key=indexs>
{{items.content}} //我想只显示前三条数据
</div></div上面这样可以输出所有的的数据 但是现在我只想让它输出前三条数据 我改成这样了v-for="(items, indexs) in item.list.slice(0, 2)"但是报错了 TypeError: Cannot read property 'slice' of undefined"这是为什么?cMList: [
{ uid: 10001, list: [
{nickname: 'aaa', content: '666', time: '2019.2.12'},
{nickname: 'aaa', content: '666', time: '2019.2.12'},
{nickname: 'aaa', content: '666', time: '2019.2.12'},
{nickname: 'aaa', content: '666', time: '2019.2.12'},
{nickname: 'aaa', content: '666', time: '2019.2.12'},
{nickname: 'aaa', content: '666', time: '2019.2.12'},
{nickname: 'aaa', content: '666', time: '2019.2.12'}
]
}
]
3 回答
慕田峪9158850
TA贡献1794条经验 获得超7个赞
是你写错了。。。
<div v-for="(item, index) in cMList" :key="index"> <div v-if="item.list" v-for="(items, indexs) in item.list.splice(0, 3)" :key="indexs"> {{items.content}} </div></div>
添加回答
举报
0/150
提交
取消