refactor: refactor api usage

This commit is contained in:
张传龙
2022-07-25 18:36:22 +08:00
parent e5768fa1e3
commit 7762e02b31
11 changed files with 34 additions and 101 deletions

View File

@@ -17,6 +17,8 @@ export function createAxios(options = {}) {
export const defAxios = createAxios()
export default createAxios()
export const testAxios = createAxios({
baseURL: import.meta.env.VITE_APP_BASE_API_TEST,
})

View File

@@ -1,5 +1,5 @@
import { lStorage } from './cache'
import { refreshToken } from '@/api/auth'
import api from '@/api'
const TOKEN_CODE = 'access_token'
const DURATION = 6 * 60 * 60
@@ -25,7 +25,7 @@ export async function refreshAccessToken() {
// token生成或者刷新后30分钟内不执行刷新
if (new Date().getTime() - time <= 1000 * 60 * 30) return
try {
const res = await refreshToken()
const res = await api.refreshToken()
if (res.code === 0) {
setToken(res.data.token)
}