Preface: In daily projects, you may need to determine the current user's operating permissions based on the data returned by the background interface. The delete button must be displayed when there is delete permission. Without this permission, the button will not be displayed or deleted. By searching for information, this function is realized through vuex. 1. Steps 1. Define buttom permissions Create Using vuex: Vue.use(Vuex) Create a vue instance const store = new Vuex.Store({ state: { buttomPermission: {} }, mutations: setPermission(state, permission) { state.buttomPermission = permission } } }) export default store 2. Define the storeimport store from './store/index.js' new Vue({ store, el: '#app', render: h => h(App) }) 3. Create permission instructions Create a new The inserted( el, bindings, vnode ) { } 4. Use the permission directive Introduce and define the <button v-permission="'add'">Add</button> import permission from './directives/permission' directives: {permission,}, 5. Delete unauthorized data In the inserted(el, bindings, vnode) { let btnPermissionValue = bindings.value; let boolean =vnode.context.$store.state.buttomPermission[btnPermissionValue]; !boolean && el.parentNode.removeChild(el); } 6. Passing in state management data Pass the state management data to the permission management through the let permissions = {} this.$store.commit("setPermission", permissions); II. Overview In general, a This is the end of this article about vue button permission control. For more relevant vue button permission control content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Comprehensive understanding of HTML Form elements
>>: Flame animation implemented with CSS3
1. Environmental preparation: Operating system: C...
Use ES6 modular development and observer mode to ...
background: Because the server deployed the flask...
Friends who have used the Linux system must have ...
vue+el-upload multiple files dynamic upload, for ...
Table of contents Manual deployment 1. Create a s...
MySQL error: Parameter index out of range (1 >...
Event response refresh: refresh only when request...
Table of contents 1 Nginx Installation 2 Configur...
The specific code for encapsulating the image cap...
Simply pull the image, create a container and run...
1. Environment VS 2019 16.9.0 Preview 1.0 .NET SD...
Ubuntu 16.04 installs the PHP7.0 environment by d...
This article shares the installation tutorial of ...
Detailed explanation of Linux LVM logical volume ...