例如添加子路径/admin
1.
vue.config.js 文件里
publicPath: "/admin/",
outputDir: 'admin',
2.
src\layout\components\Navbar.vue 文件里
async logout() {
this.$confirm('确定注销并退出系统吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$store.dispatch('LogOut').then(() => {
location.href = '/admin/index';
})
}).catch(() => {});
}
3.
src\router\index.js 文件里
export default new Router({
mode: 'history', // 去掉url中的#
base: '/admin/',
scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes
})
4.
src\utils\request.js 文件里
if (code === 401) {
if (!isRelogin.show) {
isRelogin.show = true;
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning'
}
).then(() => {
isRelogin.show = false;
store.dispatch('LogOut').then(() => {
location.href = '/admin/index';
})
}).catch(() => {
isRelogin.show = false;
});
}