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.

报错信息

console控制台报错

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.

报错分析

在一个组件模板中应该只存在一个根元素,所以在每个组件操作中都应该只有一个根元素。

1
2
3
4
<template>
<text></text>
<button v-on:click="backIndex"></button>
</template>

未修改前,一个template中存在多个根,因此报错。

故而只需要在外层套一个div或者其他元素包裹所有的元素即可解决

1
2
3
4
5
6
<template>
<view>
<text></text>
<button v-on:click="backIndex"></button>
</view>
</template>

最后更新: 2019年10月13日 22:41

原始链接: http://ldc5886.github.io/2019/05/20/uni-app%20%E6%8A%A5%E9%94%992/

× 请我吃糖~
打赏二维码