1.vue-element-admin搭建項目中實現點擊左側菜單欄獲取當前菜單的ID,我目前主要是用來做按鈕權限功能;點擊菜單獲取當前菜單的按鈕權限; 具體實現方法: 1.在src/layout/components/Sidebar/index.vue增加 watch: 方法來檢測路由變化獲取當前信息;
2.打印console.log('route watch ====>', val)看是否有自己需要的信息 (目前我需要ID信息,打印出來沒有菜單的ID)因此store/modules/permission.js中generaMenu中將需要的ID傳入meta中,那么打印console.log('route watch ====>', val)就可以獲取到ID
在src/layout/components/Sidebar/index.vue在watch中調用后端提供的根據菜單ID獲取的當前菜單的按鈕信息
4.在項目utils/index中寫公共方法看按鈕是否有權限
6.在頁面引用即可
import { formatDate, hasPermissionBtn } from '@/utils' 在methods:中寫方法 /** * 權限限制展示 */ hasPerms(perms) { return hasPermissionBtn(perms) }, 在所需要的按鈕增加v-if判斷 例如: <el-button v-if="hasPerms('newlyAdded')" type="primary" style="float:right;width:100px;" @click="AddEvent">新增</el-button>