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

當我點擊到第二個路由時,刷新當前頁面,路由依然保持不變,地址不會因刷新而跳轉到第一個路由。

1、

<router-link tag="li" v-for="(item,index) in menu" :key="item.link"

@click.native="tab(index)"

:class="{active:index == num}"

:to="{path:item.link, query:{item:index, userid: userid}}">

<span>{{item.title}}</span>

</router-link>

2、export default {

data () {

    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}});

        }

    }

}

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章