From ecf7558e8e01cf599a3f7023fc867176a451edc6 Mon Sep 17 00:00:00 2001 From: Pan Date: Tue, 6 Jun 2017 10:46:20 +0800 Subject: [PATCH] refine permission example --- src/store/modules/user.js | 10 ++++++++++ src/views/permission/index.vue | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 384a1323..a134f44f 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -132,6 +132,16 @@ const user = { Cookies.remove('Admin-Token'); resolve(); }); + }, + + // 动态修改权限 + ChangeRole({ commit }, role) { + return new Promise(resolve => { + commit('SET_ROLES', [role]); + commit('SET_TOKEN', role); + Cookies.set('Admin-Token', role); + resolve(); + }) } } }; diff --git a/src/views/permission/index.vue b/src/views/permission/index.vue index b0b95403..d11e8cd4 100644 --- a/src/views/permission/index.vue +++ b/src/views/permission/index.vue @@ -23,8 +23,9 @@ }, watch: { role(val) { - this.$store.commit('SET_ROLES', [val]); - this.$router.push({ path: '/permission/index?' + +new Date() }); + this.$store.dispatch('ChangeRole', val).then(() => { + this.$router.push({ path: '/permission/index?' + +new Date() }); + }) } } }