父传子,并且通过fatherEvent接收子组件传过来的值

<template>
<div class='father'>
<Son :fatherData="fatherData" @fatherEvent='getSonMsg' />
</div>
</template> import Son from './Son';
export default{
data(){
return{
fatherData:{
msgData:"我是父亲"
}
},
components:{
Son
},
methods:{
getSonMsg(msg){
console.log(`这是从子组件传来的msg${msg}`)
}
}

子组件接受父组件消息,并通过$emit回传父组件(当然也可以不通过watch)

<template>
<div class='son' >{msg}
<button @click='fatherEmit'></button>
</div>
</template>
<script> export default(){
name:"son',
props:{
fatherData:Object
}
data(){
return{
msg:""
}
}
},
watch:{
fatherData:function(newValue,oldValue){
this.changeData()
}
},
methods:{
changeData(){
this.$nextTick(function(){
this.msg = this.fatherData.msgData
}
}),
fatherEmit(){
this.$emit('fatherEvent','我是额子')
}
} </script>

这样就完成父子和子父之间数据的传递了

Vue2.x之父子组件数据传递的更多相关文章

  1. React中父子组件数据传递

    Vue.js中父子组件数据传递:Props Down ,  Events Up Angular中父子组件数据传递:Props Down,  Events  Up React中父子组件数据传递:Prop ...

  2. vue2.0 父子组件数据传递prop

    vue的一个核心概念就是组件,而组件实例的作用域是孤立的,所以组件之间是不能直接引用其他组件的数据的.极端点举例来说,就是可以在同一个项目中,每一个组件内都可以定义相同名称的数据. data () { ...

  3. 关于vue.js父子组件数据传递

    vue.js中使用props down,events up的原则进行父子组件间的通信,先来记录下props down,看个例子: <div id="app2"> < ...

  4. react父子组件数据传递

    子传父 1.首先父组件设定一个自定义函数 getChildDatas = (values) => { //...业务代码 } 2.将该函数暴露在子组件的引用上 <Child getChil ...

  5. vue教程3-05 vue组件数据传递、父子组件数据获取,slot,router路由

    vue教程3-05 vue组件数据传递 一.vue默认情况下,子组件也没法访问父组件数据 <!DOCTYPE html> <html lang="en"> ...

  6. Vue.js 父子组件相互传递数据

    父传子 : 子组件接收变量名=父组件传递的数据 如::f-cmsg="fmsg"  注意驼峰问题 子传父:@子组件关联的方法名 = 父组件接受的方法名 如:@func=" ...

  7. 【Vue】Vue中的父子组件通讯以及使用sync同步父子组件数据

    前言: 之前写过一篇文章<在不同场景下Vue组件间的数据交流>,但现在来看,其中关于“父子组件通信”的介绍仍有诸多缺漏或者不当之处, 正好这几天学习了关于用sync修饰符做父子组件数据双向 ...

  8. vue 父子组件属性传递

    父子组件属性传递 注意:0.谁被引用,谁就算子组件  1.属性命名最好完全小写,否则需要如下格式转换:myAttr == my-attr 2.引入的vue组件后必须通过 components 注册才能 ...

  9. Vue父子组件数据双向绑定,子组件可修改props

    第一种,子组件通过监听父组件数据,子组件改变数据之后通知给父组件 原文链接:https://blog.csdn.net/m0_37728716/article/details/81776929 父组件 ...

随机推荐

  1. tomcat apr Dockfile

    基于 centos7.4 jdk1.7 RUN yum makecache && yum --nogpgcheck -y groupinstall 'Development Tools ...

  2. php 对象 调用静态方法

    1.BNF范式 .u.op.opline_num = , &$ TSRMLS_CC); } function_call_parameter_list .u.op.opline_num?NULL ...

  3. Gen中的switch分析及lookupswitch与tableswitch指令

    int chooseNear(int i) { switch (i) { case 0: return 0; case 1: return 1; case 2: return 2; default: ...

  4. centos7-windows10 双系统安装

    win10默认, 然后压缩出来一个卷安装win7: http://www.techweb.com.cn/network/system/2016-12-21/2456741.shtml http://b ...

  5. Ceph 块设备 - 命令,快照,镜像

    目录 一.Ceph 块设备 二.块设备 rbd 命令 三.操作内核模块 四.快照基础 rbd snap 五.分层快照 六.镜像 rbd mirror 七.QEMU 八.libvirt 九.Openst ...

  6. java NIO系列教程2

    7.FileChannel Java NIO中的FileChannel是一个连接到文件的通道.可以通过文件通道读写文件. FileChannel无法设置为非阻塞模式,它总是运行在阻塞模式下. 打开Fi ...

  7. SharePoint 2013 EventHanlder工具

    之前在07的时候使用SharePoint Event Receiver Manager (2007 & 2010)来管理SharePoint的Event Handler,但是2013后作者没有 ...

  8. C++ STL使用说明

    标准模板库(Standard Template Library,STL)是一系列通用化组件的集合,包括容器(container).算法(algorithm)和迭代器(iterator). 迭代器ite ...

  9. [转]How to log queries using Entity Framework 7?

    本文转自:https://stackoverflow.com/questions/26747837/how-to-log-queries-using-entity-framework-7

  10. Xamarin学习

    慧都视频:http://training.evget.com/video/5384 极客学院视频:http://www.jikexueyuan.com/course/364.html