為什么先定義new Vue再聲明todo-item組件會失效
new Vue({
el: '#root',
data: {
inputValue : '2',
list: []
},
methods: {
handleSubmit: function(){
this.list.push(this.inputValue);
this.inputValue = ''
}
}
})
Vue.component('todo-item', {
template: '<li>item</li>'
})
el: '#root',
data: {
inputValue : '2',
list: []
},
methods: {
handleSubmit: function(){
this.list.push(this.inputValue);
this.inputValue = ''
}
}
});
2020-08-19
代碼執(zhí)行順序
2019-12-27
因為你的順序反了,你的組件都沒定義就先創(chuàng)建了一個Vue實例,那這個組件其實是沒有生效的。類似于你DOM都還沒生成就調用了操作DOM的方法