为什么先定义new Vue再声明todo-item组件会失效

来源:3-2 todolist组件拆分

qq_GunsOrRoses_0

2019-12-26 22:55

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 = ''

}

}

});


写回答 关注

2回答

  • 慕无忌3165165
    2020-08-19 11:21:17

    代码执行顺序

  • 一笑卿橙
    2019-12-27 11:29:25

    因为你的顺序反了,你的组件都没定义就先创建了一个Vue实例,那这个组件其实是没有生效的。类似于你DOM都还没生成就调用了操作DOM的方法

vue2.5入门

快速理解Vue编程理念上手Vue2.0开发。

146174 学习 · 655 问题

查看课程

相似问题