我刚刚用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.
这是我的代码.我对此很新,我无法弄清楚出了什么问题.
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>
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>
我希望有人能提供帮助!