vue $emit

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="vue.js"></script>
</head>
<body>
<div id="app">
<my-com @increase="handleAdd"></my-com> 这里的@increase 是$emit 事件

</div>
<script>
Vue.component("my-com",{
template:'<div><button @click="handleAdd">+1</button></div>',
data (){
return {
counter:0
}
},
methods:{
handleAdd(){
this.counter ++;
this.$emit('increase',this.counter)   用$emit 向上传递参数
}
}
})
new Vue({
el:"#app",
data:{

},
methods:{
handleAdd(val){
console.log(val)
}
},
components:{

}
})
</script>
</body>
</html>

原文地址:https://www.cnblogs.com/fordouble/p/7199252.html