v-for写在非template上,添加:key没有任何问题,但是写在template上就不行了,加了就报错。有些时候由于内容过多,不得不写在上面,以下是解决方法:
<template v-for="item,index in 5">
---其他标签
测试{{index}}
---其他标签
</template>
<template>
<div class="root">
<div v-for="item,index in 5" :key="index">
---其他标签
测试{{index}}
---其他标签
</div>
</div>
</template>
根据解析出来的内容,我们直接这么写,就OK了。套上了两层div