Skip to content

Commit

Permalink
✨ dynamic loading vue components
Browse files Browse the repository at this point in the history
  • Loading branch information
tookbra committed May 10, 2019
1 parent 5901363 commit 0b8733d
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 29 deletions.
1 change: 0 additions & 1 deletion src/components/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ExceptionPage from "@/components/exception";
import BasicLayout from "@/components/layout/basic-layout";
// import NavTab from "@/components/layout/navtab";

export { ExceptionPage, BasicLayout };
2 changes: 1 addition & 1 deletion src/components/layout/basic-layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default {
}
},
created() {
this.menus = this.mainMenu.find(item => item.path === "/").children;
this.menus = this.mainMenu;
},
methods: {
drawerClose() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<script>
export default {
name: "index"
name: "pageLayout"
};
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/components/login/user-login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default {
},
loginSuccess(res) {
console.log(res);
this.$router.push({ name: "login" });
this.$router.push({ name: "home" });
},
requestFailed(err) {
this.$notification["error"]({
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import store from "./store";
import "./core/use";
import "./permission";

import basicContainer from "./components/basic-container/index";
import basicContainer from "./components/layout/page-layout";

if (process.env.NODE_ENV !== "production") require("@/mock");

Expand Down
33 changes: 13 additions & 20 deletions src/mock/data/permission/super-admin.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
export const superAdminPermission = [
{
title: "首页",
key: "",
name: "index",
title: "系统管理",
key: "system",
icon: "setting",
component: "BasicLayout",
children: [
{
title: "系统管理",
key: "system",
icon: "setting",
children: [
{
title: "租户管理",
key: "tenant"
},
{
title: "角色管理",
key: "roleList"
},
{
title: "权限管理",
key: "tableList"
}
]
title: "租户管理",
key: "tenant"
},
{
title: "角色管理",
key: "roleList"
},
{
title: "权限管理",
key: "tableList"
}
]
}
Expand Down
14 changes: 13 additions & 1 deletion src/router/dynamic-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,24 @@ export const generatorDynamicRouter = () => {
*/
export const generator = (routerMap, parent) => {
return routerMap.map(item => {
if (item.component) {
console.log(222);
}
const currentRouter = {
// 路由地址 动态拼接生成如 /dashboard/workplace
path: `${(parent && parent.path) || ""}/${item.key}`,
// 路由名称,建议唯一
name: item.name || item.key || "",
// 该路由对应页面的 组件
component: constantRouterComponents[item.component || item.key],
component: item.component
? constantRouterComponents[item.component || item.key]
: function(resolve) {
require([
`../views` +
`${(parent && parent.path) || ""}/${item.key}` +
`.vue`
], resolve);
},
// meta: 页面标题, 菜单图标, 页面权限(供指令权限用,可去掉)
meta: {
title: item.title,
Expand All @@ -63,6 +74,7 @@ export const generator = (routerMap, parent) => {
closeable: true
}
};
console.log(parent);
// 为了防止出现后端返回结果不规范,处理有可能出现拼接出两个 反斜杠
currentRouter.path = currentRouter.path.replace("//", "/");
// 重定向
Expand Down
2 changes: 1 addition & 1 deletion src/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const constantRouterMap = [
{
path: "/",
component: BasicLayout,
redirect: "/home/index",
redirect: "/home",
children: [
{
path: "home",
Expand Down
2 changes: 1 addition & 1 deletion src/views/exception/403.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</template>

<script>
import { ExceptionPage } from "@/components/exception";
import { ExceptionPage } from "@/components";
export default {
components: {
Expand Down
2 changes: 1 addition & 1 deletion src/views/exception/500.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</template>

<script>
import {ExceptionPage} from "@/components/exception";
import { ExceptionPage } from "@/components";
export default {
components: {
Expand Down

0 comments on commit 0b8733d

Please sign in to comment.