import {defineStore} from "pinia/dist/pinia";
export const userPermission = defineStore('userPermission', {
state: () => {
return {
permissions: ['add', 'delete']
}
},
actions: {},
getters: {}
})
import {userPermission} from "./state/pinia-state";
let permissions = userPermission()
app.directive('permission', (el, binding) => {
if (permissions.permissions.indexOf(binding.value) < 0) {
el.parentNode.removeChild(el)
}
})
<el-row class="mb-4">
<el-button v-permission="`add`">增1</el-button>
<el-button v-permission="`delete`" type="primary">删2</el-button>
<el-button v-permission="`a1`" type="success">改3</el-button>
</el-row>
![image.png](https://i-blog.csdnimg.cn/blog_migrate/449210f2cb1f5f797f78b04465571ec9.png)