Commit a5efd63f authored by 吴冠's avatar 吴冠

优化存储方式

parent 5944a114
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
}, },
mounted(){ mounted(){
let tokenStr = window.localStorage.getItem("token") let tokenStr = window.sessionStorage.getItem("token")
if(tokenStr){ if(tokenStr){
this.showDefault = false this.showDefault = false
this.userName = window.localStorage.getItem("companyName") this.userName = window.sessionStorage.getItem("companyName")
} }
}, },
data() { data() {
...@@ -51,12 +51,12 @@ ...@@ -51,12 +51,12 @@
this.$router.push("/login/admin") this.$router.push("/login/admin")
}, },
jump(){ jump(){
let token=localStorage.getItem("token") let token=sessionStorage.getItem("token")
window.location.href=`http://192.168.200.201:8082/purchaser/Home?token=${token}` window.location.href=`http://192.168.200.201:8082/purchaser/Home?token=${token}`
// window.location.href=`http://localhost:8080/purchaser/Home?token=${token}` // window.location.href=`http://localhost:8080/purchaser/Home?token=${token}`
}, },
getUserName(){ getUserName(){
return window.localStorage.getItem("companyName"); return window.sessionStorage.getItem("companyName");
} }
}, },
......
...@@ -84,17 +84,17 @@ import {getSecond,getCategoryList,getListSSS} from '@/common/list.js' ...@@ -84,17 +84,17 @@ import {getSecond,getCategoryList,getListSSS} from '@/common/list.js'
}, },
//添加验证方法 //添加验证方法
async getSecond(){ async getSecond(){
let tokenStr = window.localStorage.getItem('token') let tokenStr = window.sessionStorage.getItem('token')
if(tokenStr){ if(tokenStr){
this.showDefault = false this.showDefault = false
const {data,code} = await getSecond() const {data,code} = await getSecond()
//code为401,失效 清空并返回至登录页 //code为401,失效 清空并返回至登录页
if(code ==401){ if(code ==401){
window.localStorage.clear() window.sessionStorage.clear()
this.$router.push("/login/user") this.$router.push("/login/user")
} }
window.localStorage.setItem("companyName",data.companyName) window.sessionStorage.setItem("companyName",data.companyName)
this.userName = window.localStorage.getItem("companyName") this.userName = window.sessionStorage.getItem("companyName")
} }
/* const {data} = await getSecond() /* const {data} = await getSecond()
console.log(data) */ console.log(data) */
...@@ -114,7 +114,7 @@ import {getSecond,getCategoryList,getListSSS} from '@/common/list.js' ...@@ -114,7 +114,7 @@ import {getSecond,getCategoryList,getListSSS} from '@/common/list.js'
}, },
//添加退出按钮 清空token //添加退出按钮 清空token
checkout(){ checkout(){
window.localStorage.clear() window.sessionStorage.clear()
this.$router.push("/login/user") this.$router.push("/login/user")
}, },
}, },
......
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
data data
} = await powerLogin(this.param) } = await powerLogin(this.param)
if (code == 200) { if (code == 200) {
localStorage.setItem("token",data); sessionStorage.setItem("token",data);
this.$message({ this.$message({
message: msg, message: msg,
type: 'success', type: 'success',
......
...@@ -12,7 +12,7 @@ const service = axios.create({ ...@@ -12,7 +12,7 @@ const service = axios.create({
// request拦截器 // request拦截器
service.interceptors.request.use(config => { service.interceptors.request.use(config => {
let token=localStorage.getItem("token") let token=sessionStorage.getItem("token")
if(token||token!=="undefined"){ if(token||token!=="undefined"){
config.headers['token']=token; config.headers['token']=token;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment