若依前后台分离vue项目放开前台页面拦截配置
使用场景某些页面不需要权限就能直接访问的页面 , 例如做个单点登录之类的。这里只需要修改2处即可
ssologin.vue代码
<template>
</template>
<script>
export default {
name: "SsoLogin",
data() {
return {
redirect: undefined,
userInfo: {
username: "",
uuid: "",
},
loading: false,
}
},
watch: {
$route: {
handler: function (route) {
this.redirect = route.query && route.query.redirect;
},
immediate: true
}
},
methods: {},
created() {
this.userInfo.uuid = this.$route.query.uuid;
this.userInfo.username = this.$route.query.username;
this.$store.dispatch("SsoLogin", this.userInfo).then(() => {
this.loading = true;
this.$router.push({path: this.redirect || "/"}).catch(() => {
});
}).catch(() => {
});
}
}
</script>
user.js添加了单点登录
import {login, logout, ssoLogin, getInfo} from '@/api/login'
SsoLogin({commit}, userInfo) {
return new Promise((resolve, reject) => {
ssoLogin(userInfo.uuid, userInfo.username).then(res => {
setToken(res.data.token)
commit('SET_TOKEN', res.data.token)
resolve()
}).catch(error => {
reject(error)
})
})
},