登录前后端联调对接

This commit is contained in:
陈淳
2022-10-12 19:00:26 +08:00
parent dd7bbb138a
commit de28fd4ca4
13 changed files with 507 additions and 97 deletions

View File

@@ -0,0 +1,13 @@
const TokenKey = 'Admin-Token'
export function getToken() {
return localStorage.getItem(TokenKey)
}
export function setToken(token:string) {
return localStorage.setItem(TokenKey, token)
}
export function removeToken() {
return localStorage.removeItem(TokenKey)
}

View File

@@ -2,6 +2,7 @@ import axios from 'axios'
// import store from '../store/index'
// import vm from '../main'
import JsonBig from 'json-bigint'
import { getToken } from '@/utils/auth'
// import VuetifyDialogPlugin from 'vuetify-dialog/nuxt/index';
const myaxios = axios.create({
// baseURL:'/'//
@@ -20,8 +21,12 @@ const myaxios = axios.create({
})
// 请求拦截器
myaxios.interceptors.request.use(function(config) {
// config.headers.Authorization = 'Bearer ' + store.state.user.token;
const isToken = (config.headers || {}).isToken === false
// 是否需要防止数据重复提交
const isRepeatSubmit = (config.headers || {}).repeatSubmit === false
if (getToken() && !isToken) {
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
}
// store.dispatch("openLoad");
return config;
}, function(error) {