vue菜鳥一枚,下載github上的代碼來框架和思路,添加自己新的代碼調試的時候,發現了一個錯誤,,具體報錯如:
error in ./src/components/page/Test.vue (Emitted value instead of an instance of Error) Vue template syntax 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. @ ./src/components/page/Test.vue 5:2-167 @ ./src/router/index.js @ ./src/main.js @ multi ./build/dev-client babel-polyfill ./src/main.js
剛開始這樣寫得時候是沒有發現啥錯誤的,我只是在后面添加一個<div></div>或是加了別的就說出現這個錯誤
<template>
<el-button type="primary">{{test1}}</el-button>
</template>
原來vue模板只能有一個根對象
所以你想要出現正常的效果,你的用一個div來或是別的標簽來包裹全部的元素
正確的寫法就是:
<template>
<div>
<el-button type="primary">haha1</el-button>
<div>hahhaa</div>
<el-input type="text" placeholder="測試一下"></el-input>
<h1>{{test1}}</h1>
</div>
</template>
