javascript - vue-router的项目中不同vue实例如何操作互相的数据
本文介绍了javascript - vue-router的项目中不同vue实例如何操作互相的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
路由配置
entry.js
router.map({
'/form': {
component: function(resolve) {
require(['./views/form'], function(form) {
resolve(form);
})
}
},
'/grid': {
component: function (resolve) {
require(['./views/grid'], function(grid) {
resolve(grid);
})
}
},
...
./view/form.js
var $http = require('../vendors/rest.js');
var Form = Vue.extend({
template: require('../template/form.html'),
data: function (transition) {
},
computed: {
},
methods: {
submit: function() {
// 这里怎么操作Grid component的data?
}
},
route: {
activate: function (transition) {
transition.next()
},
deactivate: function (transition) {
console.log('hook-example deactivated!')
transition.next()
}
}
});
module.exports = Form;
如何在form对应的component的method中操作grid component的data? 两者并不存在父子关系。
解决方案
之前有答过:
https://segmentfault.com/q/1010000004002...
但是如果用vuex最方便了
这篇关于javascript - vue-router的项目中不同vue实例如何操作互相的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文