admin 管理员组文章数量: 887031
v
1,新建store.js文件
import Vue from 'vue'import Vuex from 'vuex'import {GetUserAllAuthorization} from '@/api/permissionSetting'Vue.use(Vuex)const store = new Vuex.Store({state: {roles: [],},getters: {roles: state => state.roles,},mutations: {SET_ROLES: (state, roles) => {state.roles = roles},},actions: {// 获取用户权限getInfo({commit,state}) {return new Promise((resolve, reject) => {const UserID = sessionStorage.getItem('UserID')GetUserAllAuthorization(UserID).then(response => {const {Content} = responseconst {Author} = Contentconst roles = Author.map(el => {return el.Code})// 用户权限代码commit('SET_ROLES', roles)resolve(Content)})// });})},},})
2,新建permission.js文件
import store from '@/store';export default {inserted(el, binding, vnode) {const { value } = binding;const roles = store.getters && store.getters.roles;if (value && value instanceof Array && value.length > 0) {const permissionRoles = value;const hasPermission = roles.some(role => {return permissionRoles.includes(role);});if (!hasPermission) {el.parentNode && el.parentNode.removeChild(el);}} else {throw new Error(`need roles! Like v-permission="['admin','editor']"`);}}
};
3,需要用到的a.vue文件里
<script>import {import permission from '@/directive/permission/index';}export default {directives: {permission},name: 'a',data() {}}
在html文件中来用即可
<el-select v-permission="['1610']" v-model="TaskUserID" placeholder="全体成员">
本文标签: v
版权声明:本文标题:v 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1686538224h7531.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论