Skip to content

Commit 6b848ea

Browse files
author
shangbin
committed
update: 集成vant,可以正常渲染
1 parent 4829c39 commit 6b848ea

15 files changed

+391
-387
lines changed

src/libs/UIComponentInit.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
// 其它UI组件库应该在这里集成
22
function loadVant() {
3-
const vantLoadPromise = (() => import("vant"))();
43
(() => import("vant/lib/index.css"))();
5-
vantLoadPromise.then((vantModule) => {
6-
self.globalApp.use(vantModule);
7-
});
4+
const vantLoadPromise = (() => import("vant"))();
5+
return vantLoadPromise;
86
}
97

108
function loadAntD() {
11-
const vantLoadPromise = (() => import("ant-design-vue"))();
129
(() => import("ant-design-vue/dist/antd.css"))();
13-
vantLoadPromise.then((vantModule) => {
14-
self.globalApp.use(vantModule);
15-
});
10+
const vantLoadPromise = (() => import("ant-design-vue"))();
11+
return vantLoadPromise;
1612
}
1713

18-
loadAntD();
19-
loadVant();
14+
export default function loadCompontents() {
15+
return Promise.all([loadAntD(), loadVant()]);
16+
}

src/libs/main-panel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class MainPanelProvider {
7171
if (this.editMode) {
7272
// 渲染当前代码
7373
const readyForMoutedElement = this.createMountedElement();
74-
createBaseApp(componentOptions).mount(readyForMoutedElement);
74+
createBaseAppAsync(componentOptions).then(app => app.mount(readyForMoutedElement));
7575

7676
// 拍平数据结构
7777
this.flatDataStructure(rawDataStructure);
@@ -80,7 +80,7 @@ export class MainPanelProvider {
8080
this.enableEditMode();
8181
} else {
8282
// 渲染当前代码
83-
createBaseApp(componentOptions).mount(this.mountedEle);
83+
createBaseAppAsync(componentOptions).then(app => app.mount(this.mountedEle));
8484
}
8585

8686
return this;

src/libs/store.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ const store = createStore({
2121
}
2222
})
2323

24-
globalApp.use(store);
24+
export default function loadStore(app) {
25+
app.use(store);
26+
return app;
27+
}

src/main.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,44 @@ import {
1111
import "element-plus/dist/index.css";
1212

1313
import APP from "./App.vue";
14+
import loadCompontents from "@/libs/UIComponentInit.js";
15+
import loadStore from "@/libs/store.js";
1416

15-
function createBaseApp(renderComponent = {}) {
17+
function loadTemplate(renderComponent, loadFinished = () => {}) {
1618
const app = createApp(renderComponent);
1719
app.use(ElementPlus);
20+
loadCompontents().then((modules) => {
21+
for (let index = 0; index < modules.length; index++) {
22+
const module = modules[index];
23+
app.use(module);
24+
loadFinished(app);
25+
}
26+
});
27+
return app;
28+
}
1829

19-
app.component("question-filled", QuestionFilled);
20-
app.component("circle-plus", CirclePlus);
21-
app.component("refresh", Refresh);
22-
app.component("delete", Delete);
23-
app.component("document-copy", DocumentCopy);
24-
app.component("minus", Minus);
30+
function createBaseAppSync(renderComponent = {}) {
31+
return loadTemplate(renderComponent);
32+
}
2533

26-
return app;
34+
function createBaseAppAsync(renderComponent = {}) {
35+
return new Promise((resolve, reject) => {
36+
loadTemplate(renderComponent, (app) => {
37+
resolve(app);
38+
});
39+
});
2740
}
2841

29-
const globalApp = createBaseApp(APP);
30-
globalApp.mount("#app");
42+
const app = createBaseAppSync(APP);
3143

32-
// 内部需要同样配置的全局Vue
33-
self.createBaseApp = createBaseApp;
34-
self.globalApp = globalApp; // 内部需要使用Vuex
44+
app.component("question-filled", QuestionFilled);
45+
app.component("circle-plus", CirclePlus);
46+
app.component("refresh", Refresh);
47+
app.component("delete", Delete);
48+
app.component("document-copy", DocumentCopy);
49+
app.component("minus", Minus);
50+
51+
loadStore(app).mount("#app");
3552

36-
import("@/libs/store.js");
37-
import("@/libs/UIComponentInit.js");
53+
// 内部需要同样配置的全局Vue
54+
self.createBaseAppAsync = createBaseAppAsync;

src/map/data.index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)