Browse Source

token

master
pengjun 2 years ago
parent
commit
1b25ac02e3
  1. 4
      src/api/request.js
  2. 6
      src/utlis/istoken.js
  3. 2
      src/views/login/Login.vue

4
src/api/request.js

@ -14,8 +14,8 @@ const instance = axios.create({
//请求拦截 //请求拦截
instance.interceptors.request.use( instance.interceptors.request.use(
async function (config) { async function (config) {
console.log('old token:',localStorage.getItem("token"))
console.log('old expires_in',localStorage.getItem("expires_in"))
//console.log('old token:',localStorage.getItem("token"))
//console.log('old expires_in',localStorage.getItem("expires_in"))
await yztoken(); await yztoken();
let token = localStorage.getItem("token"); let token = localStorage.getItem("token");

6
src/utlis/istoken.js

@ -27,13 +27,13 @@ export const yztoken = async () => {
} }
) )
.then((res) => { .then((res) => {
console.log('connect/token',res.data)
//console.log('connect/token',res.data)
writetoken(res.data.expires_in); writetoken(res.data.expires_in);
window.localStorage.setItem("token", res.data.access_token); window.localStorage.setItem("token", res.data.access_token);
window.localStorage.setItem("refresh_token", res.data.refresh_token); window.localStorage.setItem("refresh_token", res.data.refresh_token);
console.log('new token:',localStorage.getItem("token"))
console.log('new expires_in',localStorage.getItem("expires_in"))
//console.log('new token:',localStorage.getItem("token"))
//console.log('new expires_in',localStorage.getItem("expires_in"))
}); });
} }

2
src/views/login/Login.vue

@ -98,7 +98,7 @@ export default {
} }
) )
.then((res) => { .then((res) => {
console.log(res.data)
//console.log(res.data)
writetoken(res.data.expires_in); writetoken(res.data.expires_in);
window.localStorage.setItem("token", res.data.access_token); window.localStorage.setItem("token", res.data.access_token);
window.localStorage.setItem("refresh_token",res.data.refresh_token); window.localStorage.setItem("refresh_token",res.data.refresh_token);

Loading…
Cancel
Save