1- # @vue-async/module-loader
2-
3- 从远程地址链接加载` 模块 ` .
4- <br >
1+ # 模块化加载
52
63``` js
74// ## 主程序 ##
85
96// 引入模块
107import ModuleLoader from ' @vue-async/module-loader' ;
118
9+ /*
10+ * 注意:ES Module需要添加到`transpile`中编译
11+ * vue-cli 请添加到 vue.config.js 中的 transpileDependencies 上
12+ * nuxtjs 请添加到 nuxt.config.js 中的 build.transpile 上
13+ */
14+
1215Vue .use (ModuleLoader);
1316
1417// 方法一
@@ -23,10 +26,10 @@ app.$moduleLoader(ModuleConfig).then(()=>{
2326 app .$mount (' #app' )
2427})
2528
26- // 方法二 (例如在 nuxtjs 的 plugin 中使用时)
29+ // 方法二 (在 nuxtjs 的 plugin 中使用时)
2730var plugin = (context ) => {
2831 // 这里需要手动注册 dynamicComponent,
29- // 子模块中才可以能过 this.$dynamicComponent.add()方法
32+ // 子模块中才可以能过 this.$dynamicComponent.add()等方法
3033 var moduleLoader =
3134 new ModuleLoader ({}).registerDynamicComponent (context .store );
3235
@@ -36,21 +39,21 @@ var plugin = (context) => {
3639 context .app .moduleLoader = moduleLoader
3740}
3841export default plugin
42+
3943```
4044``` js
4145// ## 子模块 ##
42- // index.js 入口文件
46+
47+ // main.js 入口文件
4348export default function (Vue , options ){}
4449
4550// Typescript
4651import { VueConstructor } from ' vue' ;
4752import { ModuleContext } from ' @vue-async/module-loader-typing' ;
4853
49- // 方法一调用方式
50- export default function (this : InstanceType < VueConstructor > , Vue : VueConstructor , options : Recode < string , any > = {}){}
51-
52- // 方法二调用方式
53- export default function (this : ModuleContext , Vue : VueConstructor , options : Recode < string , any > = {}){}
54+ export default function (Vue : VueConstructor , options : Recode < string , any > = {}){
55+ // do something
56+ }
5457```
5558
5659## ModuleConfig 模块配置
@@ -63,18 +66,18 @@ export default function(this:ModuleContext, Vue:VueConstructor, options: Recode<
6366 {
6467 // 模块名称:远程 umd 文件 url 地址
6568 moduleName: ' remote url' ,
66- //
6769 moduleName: {
6870 entry: ' remote url' , // 远程 umd 文件 url 地址
69- styles: [],
71+ styles: [], // 自定义样式文件(例如 ExtractTextPlugin extract:true时打成独立 css文件)
7072 args: {}
7173 }
7274 },
7375 // Object
7476 {
7577 moduleName: ' ' ,
7678 entry: ' ' ,
77- styles: []
79+ styles: [],
80+ args: {}
7881 },
7982 // Function
8083 function entry (Vue ){}
@@ -110,7 +113,7 @@ Type: `Object`
110113此参数与 ` $moduleLoaderManager ` 区别在于此参数只会传递给单个子模块调用
111114<br >
112115
113- ## 子模块上下文方法
116+ ## 模块上下文注入方法
114117` this.$componentLoader(remote url) `
115118远程加载单个组件,返回 ` Promise<VueComponent> ` , 可作为 Vue 异步组件直接加载。
116119<br >
@@ -129,7 +132,7 @@ Type: `Object`
129132` this.$dynamicComponent `
130133子模块注册动态组件到主程序 ` store ` namespace ` dynamicComponent ` 中
131134当使用方法一在 ` new Vue({}) ` 之后调用时,如果引用了 ` vuex ` 将会自动注入此方法
132- 当使用方法二在之前调用时 ,需要手动 ` registerDynamicComponent(store) ` 之后才可以被调用
135+ 当使用方法二在 Vue 实例之前调用时 ,需要手动 ` registerDynamicComponent(store) ` 之后才可以被调用
133136
134137  ;  ;  ; 方法:
135138  ;  ;  ; ` add(component, position) ` 添加组件到指定的位置
@@ -153,13 +156,13 @@ Type: `Object`
153156` addRoutes(routes:RouteConfig[]) `
154157添加路由, 主程序需要引用` vue-router ` , 此方法可以在实例化参数中被覆盖重写
155158
156- 注:当主组件引用` vue-router ` 包后,将会自动注入方法解决404问题,需要在主程序中添加一条配置 ` name ` 为 ` 404 ` ` page-not-found ` ` not-found ` 或 ` path ` 为 ` * ` 的路由后生效
159+ ##### < font color = " red " > 注:当主组件引用` vue-router ` 包后,将会自动注入方法解决404问题,需要在主程序中添加一条配置 ` name ` 为 ` 404 ` ` page-not-found ` ` not-found ` 或 ` path ` 为 ` * ` 的路由后生效</ font >
157160
158161<br >
159162<br >
160163<br >
161164
162- ## <font color =" red " >问题 </font >
165+ ## <font color =" red " >其它问题 </font >
1631661、webpack 打包 Can't resolve "module"
164167``` json
165168 {
0 commit comments