vue 子组件传值给父组件

vue 子组件传值给父组件,第1张

vue 子组件传值给父组件

子组件通过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', "我是从子组件传过来的数据呀!");
}
}
}
}
});

结果:

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/585537.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存