vue this.$router.go(-1);返回时怎么带参数
1. 声明一个空的Vue模块eventBusimport Vue from 'vue'/*** 定义空的vue实例,作为 eventbus实现非父子组件之间的通信(vue2.x中去掉了broadcast)*/var eventBus = new Vue({});export default eventBus;2.“列表页”通过eventBus.$emit传参给上一个页面...
·
1. 声明一个空的Vue模块eventBus
import Vue from 'vue'
/**
* 定义空的vue实例,作为 eventbus实现非父子组件之间的通信(vue2.x中去掉了broadcast)
*/
var eventBus = new Vue({});
export default eventBus;
2.“列表页”通过eventBus.$emit
传参给上一个页面
import eventBus from '../../../static/js/eventbus.js';
//返回
back(info){
//传递一个map,addressInfo是key,info是value
eventBus.$emit('addressInfo',info);
//调用router回退页面
this.$router.go(-1);
},
3. 页面接收参数
import eventBus from '../../../static/js/eventbus.js';
activated(){
//根据key名获取传递回来的参数,data就是map
eventBus.$on('addressInfo', function(data){
console.log(data,"data");
}.bind(this));
},
更多推荐
已为社区贡献2条内容
所有评论(0)