vue.$emit(事件名称,数据)
例子:
<html>
<head></head>
<script src="js/vue.js">
<body>
<div id="box>
<aaa></aaa>
</div>
<template id="aaa">
<span>1111</span>
<bbb @child-msg="get"></bbb>
</template>
<template id="bbb">
<h1>子组件</h1>
<input type="button" value="send" @click="send">
</template>
</body>
<script>
var vm = new Vue({
el:"#box",
data:{
a:'aaa'
},
components:{
'aaa':{
data(){
return{
msg:111,
msg2:'我是父组件元素'
}
},
template:“#aaa”,
methods:{
get(msg){
this.msg = msg
}
},
components:{
'bbb':{
data(){
return{
a:'我是子组件数据'
}
},
template:'#bbb',
methods{
send(){
this.$emit('child-msg',this.a)
}
}
}
}
}}
})
</script>
</html>