Vue2.x之父子组件数据传递
父传子,并且通过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之父子组件数据传递的更多相关文章
- React中父子组件数据传递
Vue.js中父子组件数据传递:Props Down , Events Up Angular中父子组件数据传递:Props Down, Events Up React中父子组件数据传递:Prop ...
- vue2.0 父子组件数据传递prop
vue的一个核心概念就是组件,而组件实例的作用域是孤立的,所以组件之间是不能直接引用其他组件的数据的.极端点举例来说,就是可以在同一个项目中,每一个组件内都可以定义相同名称的数据. data () { ...
- 关于vue.js父子组件数据传递
vue.js中使用props down,events up的原则进行父子组件间的通信,先来记录下props down,看个例子: <div id="app2"> < ...
- react父子组件数据传递
子传父 1.首先父组件设定一个自定义函数 getChildDatas = (values) => { //...业务代码 } 2.将该函数暴露在子组件的引用上 <Child getChil ...
- vue教程3-05 vue组件数据传递、父子组件数据获取,slot,router路由
vue教程3-05 vue组件数据传递 一.vue默认情况下,子组件也没法访问父组件数据 <!DOCTYPE html> <html lang="en"> ...
- Vue.js 父子组件相互传递数据
父传子 : 子组件接收变量名=父组件传递的数据 如::f-cmsg="fmsg" 注意驼峰问题 子传父:@子组件关联的方法名 = 父组件接受的方法名 如:@func=" ...
- 【Vue】Vue中的父子组件通讯以及使用sync同步父子组件数据
前言: 之前写过一篇文章<在不同场景下Vue组件间的数据交流>,但现在来看,其中关于“父子组件通信”的介绍仍有诸多缺漏或者不当之处, 正好这几天学习了关于用sync修饰符做父子组件数据双向 ...
- vue 父子组件属性传递
父子组件属性传递 注意:0.谁被引用,谁就算子组件 1.属性命名最好完全小写,否则需要如下格式转换:myAttr == my-attr 2.引入的vue组件后必须通过 components 注册才能 ...
- Vue父子组件数据双向绑定,子组件可修改props
第一种,子组件通过监听父组件数据,子组件改变数据之后通知给父组件 原文链接:https://blog.csdn.net/m0_37728716/article/details/81776929 父组件 ...
随机推荐
- TOMCAT开启APR模式
Tomcat支持三种接收请求的处理方式:BIO.NIO.ARP. BIO模式:阻塞式I/O操作,表示Tomcat使用传统Java I/O操作.默认情况下,Tomcat7以下版本使用BIO模式运行,由于 ...
- eclipse 使用prolog编程
第一步:在电脑上安装swi-prolog 相应环境下载地址http://www.swi-prolog.org/download/stable 第二步: eclipse-help-install new ...
- 【LOJ 2542】【PKUWC2018】 随机游走(最值反演 + 树上期望dp)
哇我太菜啦555555 不妨钦定我们需要访问的点集为$S$,在$S$已知的情况下,我们令$f(x) $表示从$x$走到点集$S$中任意一点的期望步数. 若$x∈S$,则显然$f(x)=0$,否则$f[ ...
- 数据结构---平衡查找树之B树和B+树(转)
本文转载自:http://www.cnblogs.com/yangecnu/p/Introduce-B-Tree-and-B-Plus-Tree.html 前面讲解了平衡查找树中的2-3树以及其实现红 ...
- while 语句
/* while循环 格式:while(循环保持条件){需要执行的语句} OC: int i = 0; int sum = 0; while (i <= 10) { sum = i++; } w ...
- 原生ajax封装,包含post、method方式
原生ajax封装,包含post.method方式 function ajax(method, url, data, success) { var xhr = null; try { xhr = new ...
- 慕课网Python基础学习整理
# -*- coding: utf-8 -*- """# Python的注释以 # 开头,后面的文字直到行尾都算注释;多行注释开头3个 " 结尾3个 " ...
- Python单行注释与多行注释
>>> print "hello,world"hello,world>>> 2+24#单行注释 """每行代码的后 ...
- js二维数组
1.判断是否为二维数组 function isMultiArr(arr){ return arr.every(function(element){ return element instanceof ...
- ES6-Object‘s Extends
依赖文件地址 :https://github.com/chanceLe/ES6-Basic-Syntax/tree/master/js <!DOCTYPE html> <html&g ...