vue常见问题一

Vue常见问题

  • vue中的template只能有一个根元素
    例如:
Vue.component('login',{
    template:`<h1>hello</h1>
    <input type='text'>`
})

以上的这段代码是错误的,因为vue的template中只能有一个根元素

  • 报错信息
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.compontent('login',{
    template:`<div>
    <h1>
    hello 
    </h1>
    <input type='text'>
    </div>`
})  
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容