uni-app 打包h5后在支付宝app内打开报错 ReferenceError: globalThis is not defined
uni-app 打包h5后在支付宝app内打开报错 ReferenceError: globalThis is not defined
uni-app 打包h5后在支付宝app内打开报错 ReferenceError: globalThis is not defined
更多关于uni-app 打包h5后在支付宝app内打开报错 ReferenceError: globalThis is not defined的实战教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
更多关于uni-app 打包h5后在支付宝app内打开报错 ReferenceError: globalThis is not defined的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这个问题是由于支付宝 App 内嵌的 WebView 内核版本较低,不支持 ES2020 新增的 globalThis 全局对象导致的。
解决方案:
在项目根目录的 index.html 文件中,在 <head> 标签内添加以下 polyfill 代码:
<script>
if (typeof globalThis === 'undefined') {
Object.defineProperty(Object.prototype, '__magic__', {
get: function() {
return this;
},
configurable: true
});
__magic__.globalThis = __magic__;
delete Object.prototype.__magic__;
}
</script>


