欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vue 报错:Component template should contain exactly one root element. If you are using v-if on multiple

程序员文章站 2024-01-25 20:07:16
...

vue 引入 scss 编译报错:

./node_modules/vue-loader/lib/template-compiler?{“id”:“data-v-e43c18bc”,“hasScoped”:false,“transformToRequire”:{“video”:[“src”,“poster”],“source”:“src”,“img”:“src”,“image”:“xlink:href”},“buble”:{“transforms”:{}}}!./node_modules/vue-loader/lib/selector.js?type=template&index=0!./src/components/test.vue
(Emitted value instead of an instance of Error)
Error compiling template:

<img src="…/assets/logo.png">
<van-button type=“info”>信息按钮</van-button>

- Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead.

vue 报错:Component template should contain exactly one root element. If you are using v-if on multiple

问题原因:

组件模板应该只包含一个根元素,如果有多个元素,请用一个主div包含他们

解决方法:

错误代码如下:

<template>
	<img src="../assets/logo.png">
	<van-button type="info">信息按钮</van-button>
</template>

修改后:

<template>
	<div>
		<img src="../assets/logo.png">
		<van-button type="info">信息按钮</van-button>
	</div>
</template>
相关标签: 采坑之路 Vue