Skip to content
This repository was archived by the owner on May 12, 2020. It is now read-only.

Commit f34c483

Browse files
committed
feat(login): implement logout functionality
1 parent b793af9 commit f34c483

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/layout/Material.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
<!-- Dynamic aside rendering area -->
44

55
<el-container>
6-
<el-header>header</el-header>
6+
<el-header>
7+
<el-button
8+
class="logout"
9+
type="text"
10+
@click="onLogout"
11+
>Logout</el-button>
12+
</el-header>
713
<router-view/>
814
<el-footer>footer</el-footer>
915
</el-container>
@@ -14,6 +20,12 @@
1420
export default {
1521
data () {
1622
return {}
23+
},
24+
methods: {
25+
onLogout () {
26+
this.$store.dispatch('login/userLogout')
27+
.then(() => this.$router.replace('/login'))
28+
}
1729
}
1830
}
1931
</script>

src/store/modules/login/actions.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { userLogin } from 'API'
2-
import { setTokenToLocal } from 'UTILS/storage'
2+
import { setTokenToLocal, removeTokenFromLocal } from 'UTILS/storage'
33
import types from './mutations/types'
44

55
export default {
@@ -24,5 +24,10 @@ export default {
2424
}
2525
console.error(`[Login error]: ${e.code}, ${e.msg}`)
2626
})
27+
},
28+
userLogout ({ commit }) {
29+
commit(types.SET_USERNAME, '')
30+
commit(types.SET_ACCESS_TOKEN, '')
31+
removeTokenFromLocal()
2732
}
2833
}

0 commit comments

Comments
 (0)