在私有npm包(lodash-yt)中定义:
/*修复lodash在小程序中不能使用问题*/
try { global.Array = Array } catch (e) { console.log('Array not support in MINA, skip') }
try { global.Buffer = Buffer } catch (e) { console.log('Buffer not support in MINA, skip') }
try { global.DataView = DataView } catch (e) { console.log('DataView not support in MINA, skip') }
try { global.Date = Date } catch (e) { console.log('Date not support in MINA, skip') }
try { global.Error = Error } catch (e) { console.log('Error not support in MINA, skip') }
try { global.Float32Array = Float32Array } catch (e) { console.log('Float32Array not support in MINA, skip') }
try { global.Float64Array = Float64Array } catch (e) { console.log('Float64Array not support in MINA, skip') }
try { global.Function = Function } catch (e) { console.log('Function not support in MINA, skip') }
try { global.Int8Array = Int8Array } catch (e) { console.log('Int8Array not support in MINA, skip') }
try { global.Int16Array = Int16Array } catch (e) { console.log('Int16Array not support in MINA, skip') }
try { global.Int32Array = Int32Array } catch (e) { console.log('Int32Array not support in MINA, skip') }
try { global.Map = Map } catch (e) { console.log('Map not support in MINA, skip') }
try { global.Math = Math } catch (e) { console.log('Math not support in MINA, skip') }
try { global.Object = Object } catch (e) { console.log('Object not support in MINA, skip') }
try { global.Promise = Promise } catch (e) { console.log('Promise not support in MINA, skip') }
try { global.RegExp = RegExp } catch (e) { console.log('RegExp not support in MINA, skip') }
try { global.Set = Set } catch (e) { console.log('Set not support in MINA, skip') }
try { global.String = String } catch (e) { console.log('String not support in MINA, skip') }
try { global.Symbol = Symbol } catch (e) { console.log('Symbol not support in MINA, skip') }
try { global.TypeError = TypeError } catch (e) { console.log('TypeError not support in MINA, skip') }
try { global.Uint8Array = Uint8Array } catch (e) { console.log('Uint8Array not support in MINA, skip') }
try { global.Uint8ClampedArray = Uint8ClampedArray } catch (e) { console.log('Uint8ClampedArray not support in MINA, skip') }
try { global.Uint16Array = Uint16Array } catch (e) { console.log('Uint16Array not support in MINA, skip') }
try { global.Uint32Array = Uint32Array } catch (e) { console.log('Uint32Array not support in MINA, skip') }
try { global.WeakMap = WeakMap } catch (e) { console.log('WeakMap not support in MINA, skip') }
try { global._ = _ } catch (e) { console.log('_ not support in MINA, skip') }
try { global.clearTimeout = clearTimeout } catch (e) { console.log('clearTimeout not support in MINA, skip') }
try { global.isFinite = isFinite } catch (e) { console.log('isFinite not support in MINA, skip') }
try { global.parseInt = parseInt } catch (e) { console.log('parseInt not support in MINA, skip') }
try { global.setTimeout = setTimeout } catch (e) { console.log('setTimeout not support in MINA, skip') }
export * from 'lodash-es'
2 个回复
每天只睡23h (作者) - 大前端开发的一名菜鸟
我感觉应该是import只能在模块顶层调用,我这里出现了类似变量声明提前的效果。
但是这种场景,在小程序中,我怎么才能完成一段在所有js之前执行的代码呢?
1***@qq.com
参考一下这个,你的这个问题我遇见过,已经解决了。
在uniapp中使用lodash