45 lines
1.1 KiB
Vue
45 lines
1.1 KiB
Vue
<script>
|
|
import { mapMutations, mapState } from 'vuex';
|
|
export default {
|
|
computed: {
|
|
...mapState(["hasLogin"])
|
|
},
|
|
onLaunch() {
|
|
// 缓存token
|
|
uni.getStorage({
|
|
key: "token",
|
|
success: (res) => {
|
|
this.loginIn(res.data);
|
|
}
|
|
})
|
|
// 刷新token
|
|
if (this.hasLogin) {
|
|
this.refreshToken_function();
|
|
}
|
|
},
|
|
methods: {
|
|
...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>
|
|
<style lang="scss">
|
|
/* #ifndef APP-PLUS-NVUE */
|
|
@import "/static/css/normalize";
|
|
/* 顶部自定义导航留白 */
|
|
.status_bar {
|
|
width: 100%;
|
|
height: var(--status-bar-height);
|
|
}
|
|
/* #endif */
|
|
</style>
|