[英]Vue.js: pass data from one child component to another with the same parent?
I have 2 components, both sharing a common parent.我有 2 个组件,它们共享一个共同的父级。 I want to be able to pass data from one child component to the other.我希望能够将数据从一个子组件传递到另一个。 (I am using vueJS 2) (我正在使用 vueJS 2)
The communication should be handled by the parent
component as follows:通信应由parent
组件处理如下:
this.$emit('myVarChanged', this.myVar);
<ChildOneComponent @myVarChanged="updateMyVar" />
data() { return { myVar:null } }
methods: {
updateMyVar(val){
this.myVar = val;
}
}
<ChildTwoComponent :myVar="myVar" />
props
: Child 2 获得新值作为props
:props: ['myVar']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.