this.$router.push('需要跳转到的路径名称')
this.$router.replace('需要跳转到的路径名称')
// 步数可以为正 ,也可为负数,0为刷新本页
this.$router.go('需要跳转到的步数')
项目中往往要先配置路由:
import Router from "vue-router";
const login = () =>
import ("@/pages/login"); //登录页面
const index = () =>
import ("@/pages/index"); //搜索页面
const questionnaire = () =>
import ("@/pages/questionnaire"); //调查问卷
let route = new Router({
base: process.env.HASH === "hash" ? "/" : "/test/",
mode: process.env.HASH === "hash" ? "hash" : "history",
routes: [{
path: '/:lang',
name: 'login', //登录页面
component: login,
meta: {
isNoLogin: true //无需登录信息
}
},
{
path: '/index/:lang', //搜索页面
name: 'index',
component: index,
meta: {
isOpen: true //是否可以直接访问
}
},
{
path: '/test/questionnaire/:lang',
name: 'questionnaire', //调查问卷
component: questionnaire
}
]
});
export default route;
然后再使用路由跳页
this.$router.push('需要跳转到的路径名称')
this.$router.replace('需要跳转到的路径名称')
// 步数可以为正 ,也可为负数,0为刷新本页
this.$router.go('需要跳转到的步数')
//我们的项目代码如下:
//跳到指定页面
this.$router.replace({ name: indexName });
//退一页面
this.$router.go(-1)
//去到指定页面
this.$router.push({
name: "index",
});
//可以带参数
this.$router.push({name: ' 路由的name ', params: {key: value}})
//参数取值
this.$route.params.key