在组件中 component不能写在export default中,如下是错误的:
<script>
export default {
component:('todo-item', {
props: ['title'],
template: '<li>{{ title }}<button v-on:click="$emit(\'remove\')">Remove</button></li>'
})
应该把component写在export外面,因为component是需要引入的,而不是要打包导出的,并且需把component写在export/new vue前面才有效。
正确的写法为:
<script>
//写在export外面
import Vue from 'vue';
Vue.component('todo-item', {
props: ['title'],
template: '<li>{{ title }}<button v-on:click="$emit(\'remove\')">Remove</button></li>'
});
export default {