Vue常見問題
- vue中的template只能有一個(gè)根元素
例如:
Vue.component('login',{
template:`<h1>hello</h1>
<input type='text'>`
})
以上的這段代碼是錯(cuò)誤的,因?yàn)関ue的template中只能有一個(gè)根元素
- 報(bào)錯(cuò)信息
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>`
})