原代码:

<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>
Logo

前往低代码交流专区

更多推荐