mounted;el加载时 update有数据更新时,watch
有数变化时
组件
1.全局组件:
//注册组件
Vue.component('my-component',{
template:'<h2>第一个组件</h2>'
});
//必须new 并添加作用域
new Vue({ el: '#app' })
//添加组件到html
<div id="app">
<my-component></my-component>
</div>
渲染结果:
第一个组件
2.局部组件
var app=new Vue({
el:'#app',
components:{
'components-a':template:'<h2>第一个A组件</h2>',
}
})
3.组件读取数据
var app=new Vue({
el:'#app',
components:{
template:'<h2 @click="ChangeCount">{{count}}</h2>',
data:function(){ //必须写成函数
return:{ count:0};
},
methods:{
ChangeCount:function(){
this.count++;
}
}
}
});