尝试在Vue中尝试Hello World时会出现错误
我有这个错误:
组件模板应完全包含一个根元素。如果是 在多个元素上使用v-if,使用v-else-if链接。
尝试时:
<template>
<h1>Il tuo oroscopo</h1>
<h3>{{ msg }}</h3>
</template>
<script>
export default {
data() {
return {
msg: 'Hello World!'
}
}
}
</script>
<style scoped></style>
I got this error :
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.
When try :
<template>
<h1>Il tuo oroscopo</h1>
<h3>{{ msg }}</h3>
</template>
<script>
export default {
data() {
return {
msg: 'Hello World!'
}
}
}
</script>
<style scoped></style>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须将DIV放在根本上。只有一个。
You have to put a div in root. Only one.
正如错误所说的那样,
组件模板应完全包含一个根元素。
这意味着,将模板内容包裹在单个元素中,该元素将作为根元素可用。因此,用
&lt; div&gt;
包裹将解决此错误。演示:
As error says itself
Component template should contain exactly one root element.
This means, wrapped the template content with in a single element which will be work as a root element. Hence, wrapping with a
<div>
will resolve this error.Demo :