我的菜单有两个数据库表,一个主菜单一个子菜单。我想根据对应的角色展示对应的主菜单。请问应该在前端写还是在后端写呢?具体在哪个文件里写呢?
前端生成菜单的代码如下:
<el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
<template slot="title">
<i class="el-icon-location">i>
<span>{{item.title}}span>
template>
<el-menu-item :index="it.path" v-for="it in item.sList" :key="it.id" @click="savePath(it.path)">
<template slot="title">
<i class="el-icon-location">i>
<span>{{it.title}}span>
template>
el-menu-item>
el-submenu>
后端写,登录的时候前端请求后端去获取当前用户角色所拥有的菜单
function _deepClone(source) {
let target;
if (typeof source === 'object') {
target = Array.isArray(source) ? [] : {}
for (let key in source) {
if (source.hasOwnProperty(key)) {
if (typeof source[key] !== 'object') {
target[key] = source[key]
} else {
target[key] = _deepClone(source[key])
}
}
}
} else {
target = source
}
return target
}