1、使用
2、封装全局方法,挂载在Vue实例上
3、 代码
import store from '../store'
// 自定义按钮权限控制
const hasPerms = (val) => {
// 建议做一次请求,权限列表的操作,vuex刷新数据回丢失
// 引入Vuex里边存储的权限列表
const arr = store._modules.root.state.User.orderList
let result = false
const fn = (query) => {
query.forEach(element => {
(element.url === val) && (result = true)
if (element.children && element.children.length > 0) {
// 有子权限列表递归调用
fn(element.children)
}
})
}
fn(arr)
// 返回控制条件的bool值
return result
}
export default hasPerms
引入并挂载