|
@@ -7,12 +7,43 @@
|
|
|
|
|
|
<script>
|
|
|
import Sidebar from "./layout/Sidebar";
|
|
|
-
|
|
|
+import { getRolesMenu } from "@/api/login";
|
|
|
+import router, { constantRoutes } from "@/router";
|
|
|
export default {
|
|
|
name: "App",
|
|
|
components: {
|
|
|
- Sidebar: Sidebar
|
|
|
- }
|
|
|
+ Sidebar: Sidebar,
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.asyncMenu();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ asyncMenu() {
|
|
|
+ /**
|
|
|
+ path: '/home',
|
|
|
+ name: 'home',
|
|
|
+ title: '首页',
|
|
|
+ component: () => import('@/views/home/home')
|
|
|
+ */
|
|
|
+ getRolesMenu().then((res) => {
|
|
|
+ console.log(res);
|
|
|
+ let asyncRouter = res.data.map((v) => {
|
|
|
+ return {
|
|
|
+ path: v.path,
|
|
|
+ name: v.name,
|
|
|
+ title: v.title,
|
|
|
+ component: () => import(`@/views/${v.url}`),
|
|
|
+ };
|
|
|
+ });
|
|
|
+ console.log(router);
|
|
|
+ console.log("asyncRouter");
|
|
|
+ console.log(asyncRouter);
|
|
|
+ let allRouter = constantRoutes.concat(asyncRouter);
|
|
|
+ router.addRoutes(allRouter);
|
|
|
+ router.options.routes = allRouter;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ },
|
|
|
};
|
|
|
</script>
|
|
|
|