【发布时间】:2018-03-09 07:47:39
【问题描述】:
我有组件 A,它有 2 个子组件 C1 和 C2。在 C1 组件中,有一个函数可以从 C2 中的相同源获取数据。 对于C1
<template>
</template>
<script>
export default {
url = 'abc.com';
name: 'c',
data () {
return {
users:'',
}},
methods: {
getData: function () {
$.get(url, function( data ) {
this.users = data;
var ab = this.users.ab ;
var pq = this.users.pq ;
)};
}}
}
</script>
对于 C2
<template>
</template>
<script>
export default {
url = 'abc.com';
name: 'c',
data () {
return {
users:'',
}},
methods: {
getData: function () {
$.get(url, function( data ) {
this.users = data;
var cd = this.users.cd ;
var rs = this.users.rs ;
)};
}}
}
</script>
AND我还有另一个组件 D
<template>
</template>
<script>
export default {
data () {
return {
}},
methods: {
showDataABCD: function () {
// here I want to access all data of users object of C1 and C2]
// especially ab, cd
},
showDataPQRS: function () {
// here I want to access all data of users object of C1 and C2
//especially PQ, RS
}
}
</script>
在这个 D 组件中,我需要访问这两个组件的对象。我可以使用状态或任何其他可能的方式吗?
【问题讨论】:
-
不,我认为这个有点棘手。无法使用事件总线。
标签: javascript vue.js vuejs2