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
Recently, a service has an alarm, which has made ...
Table of contents 1. Script vim environment 2. Ho...
Preface In Linux kernel programming, you will oft...
/****************** * Advanced character device d...
question For a given MySQL connection, how can we...
Table of contents Preface Implementation ideas Im...
CSS display property Note: If !DOCTYPE is specifi...
1. Press win + R and type cmd to enter the DOS wi...
Web page WB.ExecWB control printing method Copy c...
There are three pages A, B, and C. Page A contains...
On the mobile side, flex layout is very useful. I...
Writing method 1: update sas_order_supply_month_p...
Since I often install the system, I have to reins...
Table of contents Preface start step Troubleshoot...
Table of contents 1. Download MySQL 2. Unzip the ...