vue3设定菜单按钮自定义指令权限(v-permission="'add'")
////按钮权限 app.directive('permission',{ mounted(el,binding){ let type = binding.value||''; let status = false; ////获取当前的this实例 let vm:any = binding.instance; ////当前菜单对应的路由信息 let route = vm.$route; ///根据路由信息获取菜单权限信息,可获取到当前菜单的所有信息
///这里表示用户所拥有的所有权限 let permissionBtns = ['edit','delete','submit','publish']; permissionBtns.forEach((item:any)=>{ if(type==item){ status = true; } }) if(!status){ el.style.display = 'none' } } })