子组件通过this.$emit("event",[args,....]),传值给父组件
HTML部分:
<div id="app">
<tmp1 @func="test"></tmp1>
</div>
JS部分:
var app = new Vue({
el: "#app",
data: {},
methods: {
test(data) {
console.log("父组件中的方法---", data)
}
},
components: {
"tmp1": {
template: `<div>
<h3>子组件h3</h3>
<button @click="myClick">子组件的按钮</button>
</div>`,
methods: {
myClick() {
this.$emit('func', "我是从子组件传过来的数据呀!");
}
}
}
}
});
结果: