vue 導航名字切換,刷新頁面,路由頁面保持一致

當我點擊到第二個路由時,刷新當前頁面,路由依然保持不變,地址不會因刷新而跳轉到第一個路由。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}});

        }

    }

}

若有更好的解決方案,歡迎討論哈~

相關文章
相關標籤/搜索