Skip to content

Commit ecf7558

Browse files
committed
refine permission example
1 parent 703c0c5 commit ecf7558

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/store/modules/user.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ const user = {
132132
Cookies.remove('Admin-Token');
133133
resolve();
134134
});
135+
},
136+
137+
// 动态修改权限
138+
ChangeRole({ commit }, role) {
139+
return new Promise(resolve => {
140+
commit('SET_ROLES', [role]);
141+
commit('SET_TOKEN', role);
142+
Cookies.set('Admin-Token', role);
143+
resolve();
144+
})
135145
}
136146
}
137147
};

src/views/permission/index.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
},
2424
watch: {
2525
role(val) {
26-
this.$store.commit('SET_ROLES', [val]);
27-
this.$router.push({ path: '/permission/index?' + +new Date() });
26+
this.$store.dispatch('ChangeRole', val).then(() => {
27+
this.$router.push({ path: '/permission/index?' + +new Date() });
28+
})
2829
}
2930
}
3031
}

0 commit comments

Comments
 (0)