wechat
lgyg 2023-09-11 00:13:28 +08:00
parent 6510250482
commit b7359cfb58
5 changed files with 19 additions and 3 deletions

View File

@ -1,7 +1,16 @@
<script> <script>
import store from './store/index.js'
export default { export default {
onLaunch: function() { onLaunch: function() {
console.log('App Launch') console.log('App Launch')
if(!(store.state.user_access_token&&store.state.userInfo['id'])){//
uni.redirectTo({
url:'/pages/login/login'
})
}else{
// console.log(store.state.user_access_token)
}
}, },
onShow: function() { onShow: function() {
console.log('App Show') console.log('App Show')

View File

@ -17,3 +17,4 @@ const app = new Vue({
...App ...App
}) })
app.$mount() app.$mount()

View File

@ -36,7 +36,9 @@ export default {
password: '' // password: '' //
}; };
}, },
onLoad() {}, onLoad() {
},
methods: { methods: {
// //
login() { login() {

View File

@ -89,7 +89,7 @@
<script> <script>
import {mapGetters,mapActions} from 'vuex' import {mapGetters,mapActions} from 'vuex'
import {USER_INFO} from '@/store/mutation-types.js' import {USER_INFO} from '@/store/mutation-types.js'
import {showLoading,toast,setStorage,stringHide} from '@/com/utils.js' import {showLoading,toast,setStorage,stringHide,clearStorageSync} from '@/com/utils.js'
export default { export default {
data() { data() {
return { return {
@ -146,9 +146,12 @@
handleLoginOut(){ handleLoginOut(){
this.$http.delete('/api/users/logout').then(({data})=>{ this.$http.delete('/api/users/logout').then(({data})=>{
if(data.code==200){ if(data.code==200){
clearStorageSync();
uni.reLaunch({ uni.reLaunch({
url:'/pages/login/login' url:'/pages/login/login'
}) })
}else{
toast('退出失败');
} }
}).catch(()=>{ }).catch(()=>{
uni.reLaunch({ uni.reLaunch({

View File

@ -20,7 +20,8 @@ const store = new Vuex.Store({
console.log(val,'createPersistedState') // value值为当前state中的所有值对象 console.log(val,'createPersistedState') // value值为当前state中的所有值对象
// return什么localstorage中的key值为vuex的value值就是什么而且是实时与state中的值保持同步 // return什么localstorage中的key值为vuex的value值就是什么而且是实时与state中的值保持同步
return { return {
userInfo: val.userInfo userInfo: val.userInfo,
user_access_token:val.user_access_token
} }
} }
}) })