This commit is contained in:
Gdpao
2020-08-05 21:06:29 +08:00
parent a47238a7a4
commit c4c11781fb
15 changed files with 305 additions and 159 deletions

21
App.vue
View File

@@ -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>