首先,在导入 loadsh 之前先创建一个文件进行导入
1. 在 utils 文件夹中创建一个文件 lodash-fix.js
2. 将下方内容复制到创建的文件 lodash-fix.js 中
/*fix.js*/
// 解决小程序使用lodash问题
global.Object = Object
global.Array = Array
// global.Buffer = Buffer
global.DataView = DataView
global.Date = Date
global.Error = Error
global.Float32Array = Float32Array
global.Float64Array = Float64Array
global.Function = Function
global.Int8Array = Int8Array
global.Int16Array = Int16Array
global.Int32Array = Int32Array
global.Map = Map
global.Math = Math
global.Promise = Promise
global.RegExp = RegExp
global.Set = Set
global.String = String
global.Symbol = Symbol
global.TypeError = TypeError
global.Uint8Array = Uint8Array
global.Uint8ClampedArray = Uint8ClampedArray
global.Uint16Array = Uint16Array
global.Uint32Array = Uint32Array
global.WeakMap = WeakMap
global.clearTimeout = clearTimeout
global.isFinite = isFinite
global.parseInt = parseInt
global.setTimeout = setTimeout
// module.exports global
3. 在导入的 loadsh 页面中同时导入 上方文件
import "../../utils/lodash-fix";
import _ from "lodash";