App.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <div id="app">
  3. <Sidebar></Sidebar>
  4. <router-view />
  5. </div>
  6. </template>
  7. <script>
  8. import Sidebar from "./layout/Sidebar";
  9. import { getRolesMenu } from "@/api/login";
  10. import router, { constantRoutes } from "@/router";
  11. export default {
  12. name: "App",
  13. components: {
  14. Sidebar: Sidebar,
  15. },
  16. created() {
  17. this.asyncMenu();
  18. },
  19. methods: {
  20. asyncMenu() {
  21. /**
  22. path: '/home',
  23. name: 'home',
  24. title: '首页',
  25. component: () => import('@/views/home/home')
  26. */
  27. getRolesMenu().then((res) => {
  28. console.log(res);
  29. let asyncRouter = res.data.map((v) => {
  30. return {
  31. path: v.path,
  32. name: v.name,
  33. title: v.title,
  34. component: () => import(`@/views/${v.url}`),
  35. };
  36. });
  37. console.log(router);
  38. console.log("asyncRouter");
  39. console.log(asyncRouter);
  40. let allRouter = constantRoutes.concat(asyncRouter);
  41. router.addRoutes(allRouter);
  42. router.options.routes = allRouter;
  43. });
  44. },
  45. },
  46. };
  47. </script>
  48. <style>
  49. #app {
  50. font-family: Avenir, Helvetica, Arial, sans-serif;
  51. -webkit-font-smoothing: antialiased;
  52. -moz-osx-font-smoothing: grayscale;
  53. text-align: center;
  54. color: #2c3e50;
  55. margin-top: 60px;
  56. }
  57. </style>