源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

vuejs父子组件之间数据交互详解

  • 时间:2020-07-19 04:54 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:vuejs父子组件之间数据交互详解
父子组件之间的数据交互遵循: props down - 子组件通过props接受父组件的数据 events up - 父组件监听子组件$emit的事件来操作数据 [b]示例[/b] 子组件的点击事件函数中$emit自定义事件
export default {
 name: 'comment',
 props: ['issue','index'],
 data () {
 return {
  comment: '',
 }
 },
 components: {},
 methods: {
 removeComment: function(index,cindex) {
  this.$emit('removeComment', {index:index, cindex:cindex});
 },
 saveComment: function(index) {
  this.$emit('saveComment', {index: index, comment: this.comment});
  this.comment="";
 }
 },
 //hook 
 created: function () {
 //get init data

 }

}

父组件监听事件
[url=https://cn.vuejs.org/v2/guide/migration.html#dispatch-%E5%92%8C-broadcast-%E6%9B%BF%E6%8D%A2]$dispatch 和 $broadcast替换[/url] [/list]  以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部