gdpaoup
This commit is contained in:
21
App.vue
21
App.vue
@@ -1,6 +1,9 @@
|
||||
<script>
|
||||
import { mapMutations } from 'vuex';
|
||||
import { mapMutations, mapState } from 'vuex';
|
||||
export default {
|
||||
computed: {
|
||||
...mapState(["hasLogin"])
|
||||
},
|
||||
onLaunch() {
|
||||
// 缓存token
|
||||
uni.getStorage({
|
||||
@@ -9,9 +12,23 @@
|
||||
this.loginIn(res.data);
|
||||
}
|
||||
})
|
||||
// 刷新token
|
||||
if (this.hasLogin) {
|
||||
this.refreshToken_function();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapMutations(['loginIn'])
|
||||
...mapMutations(['loginIn']),
|
||||
// 刷新token
|
||||
refreshToken_function(){
|
||||
this.$u.api.refreshToken({}).then((res) => {
|
||||
// console.log(res);
|
||||
if (res.errCode == 0) {
|
||||
let token = res.data.token;
|
||||
uni.setStorageSync('token', token);//存储toke值
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user