vue跳转的两种方式:页面间的跳转及跳转至页面的某一特定值

方法一:

<div class="expert" @click="this.$router.push('/expertDatabase');"></div>

直接运用路由的push方式,只要在index.js文件里配置了路由,即可跳转成功

const routes = [
  {
        // 专家库
        path: "/expertDatabase",
        name: "expertDatabase",
        component: () =>
            import ( /* webpackChunkName: "map" */ "../components/expertDatabase/expertDatabase.vue")
  }
];

方法二:
由于需要跳转至某页面,且需要定位于第二个tab时
跳转按钮页:

<div class="button flex-h" @click="authentication"></div>

methods中:

authentication() {
            this.$emit('switch-component', 'Tab4Component');
            this.$router.push({ name: 'personalInformation', params: { component: "Tab4Component", index: 3 } });
            // this.$router.push('/personalInformation');
            console.log('b');
        },

展示页面的methods:

switchComponent(componentName) {
            // alert(1)
            // 在此处根据需要进行切换展示的逻辑处理
            this.rightContentComponent = componentName;
            // this.currentTab = 2;
            if (this.rightContentComponent === 'Tab1Component') {
                this.currentTab = 0;
            } else if (this.rightContentComponent === 'Tab2Component') {
                this.currentTab = 1;
            } else if (this.rightContentComponent == 'Tab3Component') {
                this.currentTab = 2;
            } else if (this.rightContentComponent === 'Tab4Component') {
                this.currentTab = 3;
            }
            console.log('切换至组件: ' + componentName);
            console.log(this.currentTab);
        },
updateRightContentComponent() {
            if (this.currentTab === 0) {
                this.rightContentComponent = Tab1Component;
            } else if (this.currentTab === 1) {
                this.rightContentComponent = Tab2Component;
            } else if (this.currentTab === 2) {
                this.rightContentComponent = Tab3Component;
            } else if (this.currentTab === 3) {
                this.rightContentComponent = Tab4Component;
            }
        },

created:

created() {
        if (this.$route.params.index != undefined) {
            this.currentTab = parseInt(this.$route.params.index);
            this.updateRightContentComponent()
        }
    }

也就是当创建的时候判断参数是否有值,如果有则更新标签的值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值