当前位置:网站首页>小程序动态加载分包文件及根路径处理
小程序动态加载分包文件及根路径处理
2022-08-03 05:26:00 【dd00bb】
小程序根目录创建 require_file.js
// 公共函数库
import util from './utils/util'
export default {
// 公共函数库
util,
/** * 加截模型文件 * @param {数据模型文件路径 'index/IndexModel.js' } modelPath * @param {分包名称 'packageA'} package_name */
requireModel: (modelPath, package_name = "") => {
// 基路径
const base_path = "/pages/"
const {
default: modelName
} = require(`./${
package_name}${
base_path}${
modelPath}`)
return new modelName()
},
/** * 加截公共模型文件 * @param {数据模型文件路径 'Https.js' } modelPath * @param {分包名称 'packageA'} package_name */
requireCommon: (modelPath, package_name = "") => {
// 基路径
const base_path = "/class/"
const {
default: modelName
} = require(`./${
package_name}${
base_path}${
modelPath}`)
return new modelName()
}
}
/pages/index/index.js 中引入公共库文件及模型文件
//index.js
//获取应用实例
const app = getApp()
import rf from "../../require_file.js"
// 引入公共库文件
const util = rf.util
const common = rf.requireCommon('Common.js')
//引入模型文件
const index_model = rf.requireModel('index/IndexModel.js')
const search_model = rf.requireModel('search/SearchModel.js')
Page({
......
})
/pages/index/IndexModel.js 模型文件中引入公共库文件
import rf from "../../require_file"
// 引入网格请求公共库
const https = rf.requireCommon('Https.js')
class IndexModel {
/** * 构造函数 */
constructor() {
this.https = https
}
}
边栏推荐
- 常见的电子元器件分类介绍
- Automatic ticket issuance based on direct reduction of China Southern Airlines app
- 什么是参数化设计,通过实操了解一下? | SOLIDWORKS 操作视频
- g++ parameter description
- 802.1AS的SystemIdentity理解
- 【面试准备】游戏开发中的几个岗位分别做什么&考察侧重点
- ZEMAX | 如何使用ZOS-API创建自定义操作数
- 【C语言】斐波那契数列
- How the world's leading medical technology company maximizes design productivity | SOLIDWORKS Product Exploration
- 内网渗透信息收集
猜你喜欢
随机推荐
数组与字符串8-最长回文子串
ZEMAX | 如何创建复杂的非序列物体
C语言中打印字符数组出现乱码的问题(烫烫烫)
classpath: comparison with classpath*
二分查找2 - x的平方根
五、int和Integer有什么区别?
用DirectX12绘制一个几何体的程序详述
IP数据包的格式(1)
Typora
大学毕业后,零基础想转行成为一名3D建模师,现在该做什么?
002_旭日X3派初探:TogetherROS安装
classpath:与classpath*的比较
二分查找6 - 寻找峰值
001_旭日X3派初探:开箱测试
Makefile.am:24: error: Libtool library used but ‘LIBTOOL‘ is undefined
【C语言】斐波那契数列
数组与字符串11-反转字符串
2021-04-23
【记录】把json的所有key转换成小写
Automatic ticket issuance based on direct reduction of China Southern Airlines app









