vue2.0父子组件间传递数据的方法
更新时间:2018年08月16日 09:59:06 作者:5649498
本文通过一个小例子给大家介绍了vue2.0父子组件间传递数据的方法,需要的朋友参考下吧
关于父子组件之间传递数据其实文档上都说得很明白。
但是如果完全不懂的人做计也看不懂,下面是一个小例子,有两个文件
1.parent.vue
<template> <child :child-msg="msg" @ok="event"></child> </template> <script> import child from './child.vue'; export default { data(){ return{ msg:'hello worldgogo' } }, components:{ child }, methods:{ event(val){ console.log(val); } } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> </style>
2.child.vue
<template> <p>{{childMsghello}}</p> </template> <script> export default { props: ['childMsg'], data(){ return{ childMsghello:this.childMsg+'this is child' } }, created(){ //自定义事件,并且给监听此事件的回调函数的值设为200 this.$emit('ok','200'); } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> </style>
总结
以上所述是小编给大家介绍的vue2.0父子组件间传递数据的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
相关文章
Vue3+TypeScript报错:无法找到模块xx的声明文件问题
这篇文章主要介绍了Vue3+TypeScript报错:无法找到模块xx的声明文件问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2023-11-11electron dialog.showMessageBox的使用案例
Electron Dialog 模块提供了api来展示原生的系统对话框,本文主要介绍了electron dialog.showMessageBox的使用案例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2023-08-08
最新评论