一聚教程网:一个值得你收藏的教程网站

热门教程

vue根据进入的路由进行原路返回的方法

时间:2022-06-25 15:37:01 编辑:袖梨 来源:一聚教程网

情景:

a---------->c 点击返回,希望返回到a

b---------->c 点击返回,希望返回到b

解决方案:

a页面,加from字段

PubSub.subscribe('table-view', function(msg, args) {
 var rowData = args[0], rowIndex = args[1];
 //跳转详情页
 this.$router.push({
 name: 'viewAdvertiseDetails',
 query: {
 id: this.$route.query.id,
 adsenseCampaignId: rowData.id,
 from: 'viewAdvertise',
 },
 })
}.bind(this));

b页面,加from字段

PubSub.subscribe('table-view', function(msg, args) {
 var rowData = args[0], rowIndex = args[1];
 this.$router.push({
 name: 'viewAdvertiseDetails',
 query: {
 id: this.$route.query.id,
 adsenseCampaignId: rowData.id,
 from: 'setAdvertise',
 },
 })
}.bind(this));

c页面:

back: function() {
 if(this.$route.query.from==='viewAdvertise'){
 this.$router.push({
 name: 'viewAdvertise',
 query: {
 id: this.$route.query.id
 },
 })
 }else if(this.$route.query.from==='setAdvertise'){
 this.$router.push({
 name: 'setAdvertise',
 query: {
 id: this.$route.query.id
 },
 })
 }
}

热门栏目