当我点击到第二个路由时,刷新当前页面,路由依然保持不变,地址不会因刷新而跳转到第一个路由。this
一、spa
<router-link tag="li" v-for="(item,index) in menu" :key="item.link"router
@click.native="tab(index)"three
:class="{active:index == num}"路由
:to="{path:item.link, query:{item:index, userid: userid}}">it
<span>{{item.title}}</span>io
</router-link>function
二、export default {class
data () {cli
return {
menu: [{
link: '/tabone',
title: '待缴费'
},{
link: '/tabtwo',
title: '办理中'
},{
link: '/tabthree',
title: '已办结'
}],
num: 0
},
methods: {
tab: function (index) {
this.num=index;
}
},
mounted: function(){
if(this.$route.query.item){
this.num = this.$route.query.item;
if(this.num == 0) {
this.router_name = 'tabone';
} else if(this.num == 1) {
this.router_name = 'tabtwo';
} else if(this.num == 2) {
this.router_name = 'tabthree';
}
this.$router.push({path:'/' + this.router_name, query:{item: this.num, userid: this.userid}});
}else{
this.num = 0;
this.$router.push({path:'/tabone', query:{item: this.num, userid: this.userid}});
}
}
}
若有更好的解决方案,欢迎讨论哈~