标签:func dispatch tor null methods turn state 流程 dir
先修改用户退出,中午有点困先改简单的
退出代码在src\layout\components\Navbar.vue代码如下,讲流程这里不需要修改
methods: { toggleSideBar() { this.$store.dispatch(‘app/toggleSideBar‘) }, async logout() { await this.$store.dispatch(‘user/logout‘) this.$router.push(`/login?redirect=${this.$route.fullPath}`) } }
退出方法调用store\user.js的logout及resetToken,官方提供示例是post方式,abp退出是get方式请求
logout({ commit, state, dispatch }) { return new Promise((resolve, reject) => { logout(state.token).then(() => { commit(‘SET_TOKEN‘, ‘‘) commit(‘SET_ROLES‘, []) removeToken() resetRouter() // reset visited views and cached views // to fixed https://github.com/PanJiaChen/vue-element-admin/issues/2485 dispatch(‘tagsView/delAllViews‘, null, { root: true }) resolve() }).catch(error => { reject(error) }) }) },
直接修改为
logout({ commit, state }) { return new Promise((resolve, reject) => { removeToken() resetRouter() commit(‘RESET_STATE‘) resolve() }) },
把src\api\user.js中的logout方法访问url修改为以下代码
export function logout() { return request({ url: ‘/api/account/logout‘, method: ‘get‘ }) }
最后一步清除Token
resetToken({ commit }) { return new Promise(resolve => { removeToken() // must remove token first commit(‘RESET_STATE‘) resolve() }) }
测试点退出,返回登录页,并将cookie中的token清除成功
Abp Vnext3 vue-admin-template(二用户退出)
标签:func dispatch tor null methods turn state 流程 dir
原文地址:https://www.cnblogs.com/liessay/p/13244546.html