vue报错:the template root disallows ‘v-for‘ directives解决办法
原代码:<template><div v-for="(item, index) in apps" :key="index"> {{ item.name}}</div></template >报错:the template root disallows 'v-for' directives原因:根元素只能有一个,v-for是个循环,它返回更多的元素,所
·
原代码:
<template>
<div v-for="(item, index) in apps" :key="index"> {{ item.name}}</div>
</template >
报错:
the template root disallows 'v-for' directives
原因:
根元素只能有一个,v-for是个循环,它返回更多的元素,所以v-for放在根元素上Vue会不知道怎么渲染。
代码改进:(添加根节点)
<template>
<div>
<div v-for="(item, index) in apps" :key="index"> {{ item.name}}</div>
</div>
</template>
更多推荐
已为社区贡献16条内容
所有评论(0)