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.

时间:2023-12-24 11:55:01

运行代码时,一直报错:

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 elements, use v-else-if to chain them instead.

最后修改为

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.

就可以正常运行了