基于vue-element-admin开发,当点击退出登录,会清空本地存储,项目代码如下
src\layout文件
async logout() {
await this.$store.dispatch('user/logout')
var storage = window.localStorage
storage.clear()
this.$router.push(`/login?redirect=${this.$route.fullPath}`)
}
关闭会话清空本地存储的代码已经有了,我们只需要在
App.vue文件里给页面绑定关闭后触发事件
<template>
<div id="app">
<router-view />
</div>
</template>
<script>
export default{
name: 'App',
mounted() {
window.onbeforeunload = function(e) {
const storage = window.localStorage
storage.clear()
}
}
}
这么写了以后发现页面刷新后也会触发onbeforeunload然后清空所有信息,能力有限,参考了这个大佬的文章,解决了
http://t.csdn.cn/LxFOx