|
@@ -0,0 +1,56 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <el-button v-permission="['admin']">admin按钮</el-button>
|
|
|
+ <el-button v-permission="['zayu']">zayu按钮</el-button>
|
|
|
+ <el-button v-permission="['zayu1']">zayu1按钮</el-button>
|
|
|
+ <el-button v-permission="['zayu1','zayu2']">zaui1按钮zayu2按钮</el-button>
|
|
|
+ <hr />
|
|
|
+ <el-input v-model="role" placeholder="输入角色名字"></el-input>
|
|
|
+ <el-button @click="setRole">设置角色</el-button>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import store from "@/store";
|
|
|
+import { mapActions } from "vuex";
|
|
|
+export default {
|
|
|
+ name: "asyncTest",
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ role: ""
|
|
|
+ };
|
|
|
+ },
|
|
|
+ directives: {
|
|
|
+ permission: {
|
|
|
+ inserted(el, binding) {
|
|
|
+ //非管理员的都会被删除
|
|
|
+ let roles = binding.value;
|
|
|
+ let nowRole = store.getters.permission_role; //获取当前权限
|
|
|
+ if (roles.indexOf(nowRole) == -1) {
|
|
|
+ el.parentNode && el.parentNode.removeChild(el); //删除自己
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ getRole() {
|
|
|
+ return {
|
|
|
+ role: "admin"
|
|
|
+ };
|
|
|
+ },
|
|
|
+ ...mapActions(["setPermissionRole"]),
|
|
|
+ setRole() {
|
|
|
+ this.setPermissionRole(this.role);
|
|
|
+ console.log(store.getters.permission_role);
|
|
|
+ this.$message({
|
|
|
+ type:'success',
|
|
|
+ message:"更新成功,请切换一下页面,查看更新状态",
|
|
|
+ duration:1000
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style>
|
|
|
+</style>
|