父子组件通信:
子组件
<world @ww=“aa” user=“liu"pass=“qwe” age=18> world>
组件创建
Vue.component(“world”,{
props:{
user:{//获取父组件参数
type:String
},
pass:{
type:String
},
age:{
type:Number
}
},
template:”{{user}}{{pass}}{{age}}<button @click=‘a’>d button>",
methods:{
a:function(){
this.$emit(“ww”,this.user)//监听父组件方法@ww=“aa”
}
}
})
父组件
new Vue({
el:"#app",
data:{
a:1
},
methods:{
aa:function(value){//获取子组件参数
console.log(value) }
}
});