方法一:
<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()
}
}
也就是当创建的时候判断参数是否有值,如果有则更新标签的值