Nie*_*eck 9 javascript webpack vue.js
我刚刚用VueJS和Vue-loader创建了我的第一个项目.
所以我制作了第一个显示简单消息的组件,当我发出一条消息时它工作正常,但是当我发出多条消息时我收到错误:
(Emitted value instead of an instance of Error)
Error compiling template:
<message>This is a small message!</message>
<message>Another one</message>
- 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.
Run Code Online (Sandbox Code Playgroud)
这是我的代码.我对此很新,我无法弄清楚出了什么问题.
App.vue
<template>
<message>This is a small message!</message>
<message>Another one</message>
</template>
<script>
import Message from './Components/Message.vue';
export default {
name: 'app',
components: {
Message,
},
data () {
return {
}
}
}
</script>Run Code Online (Sandbox Code Playgroud)
Message.Vue
<template>
<div class="box">
<p>
<slot></slot>
</p>
</div>
</template>
<script>
export default {
}
</script>
<style>
.box { background-color: #e3e3e3; padding: 10px; border: 1px solid #c5c5c5; margin-bottom: 1em;}
</style>Run Code Online (Sandbox Code Playgroud)
我希望有人能提供帮助!
Cob*_*way 16
该错误非常明显.每个组件中只应有一个根元素.所以只需将所有内容打包成div.
<template>
<div>
<message>This is a small message!</message>
<message>Another one</message>
</div>
</template>
Run Code Online (Sandbox Code Playgroud)