1.获取数据
使用this.$router.options.routes 来获取全部路由
需要经过过滤获取路由的属性path (路径),children (是否含有子路由) ,meta.title (汉字的名字)
getrouter() {
// 弹窗 获取菜单 路由 首先调用
this.$router.options.routes.filter((element) => {
if (element.meta) {
this.routerlist.push(element);
}
});
this.treeData = this.generateRoutes(this.routerlist);
},
generateRoutes(routes) {
// 处理路由
const res = [];
for (let route of routes) {
if (route.hidden) {
continue;
}
const onlyOneShowingChild = this.onlyOneShowingChild(
route.children,
route
);
if (route.children && onlyOneShowingChild && !route.alwaysShow) {
route = onlyOneShowingChild;
}
const data = {
// path: path.resolve(basePath, route.path),
path: route.path,
title: r