angular - Ionic 3 FireReader 不工作,但 Ionic 4 可以
问题描述
我在两台不同的计算机上构建了我的 Ionic 项目并得到了不同的结果。
第一台电脑:Ionic Info
离子:
离子(离子 CLI):4.2.1(/usr/local/lib/node_modules/ionic)离子框架:离子角 3.9.2 @ionic/app-scripts:3.2.0
科尔多瓦:
cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1) Cordova Platforms : android 7.1.1 Cordova Plugins : 没有列入白名单的插件(总共 19 个插件)
系统:
NodeJS:v8.11.3 (/usr/bin/node) npm:6.2.0 操作系统:Linux 4.15
FileReader 仅在我将 await 放入 reader.readAsDataURL(); 时才起作用;
第二台电脑:
离子信息
cli 包:(/usr/local/lib/node_modules)
@ionic/cli-utils : 1.19.2 ionic (Ionic CLI) : 3.20.0
全局包:
cordova (Cordova CLI) : 8.0.0
本地包:
@ionic/app-scripts : 3.1.8 Cordova Platforms : ios 4.5.4 Ionic Framework : ionic-angular 3.9.2
我的代码:
async downloadFromURL(fileName, mimeType, url){
return new Promise((resolve,reject) => {
try{
var self = this;
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType='blob';
xhr.onloadend = async function(e) {
if (xhr.status == 200)
{
var reader = new FileReader();
reader.onloadend = async function(event){
var response = self.insertFile({
'type': mimeType,
'title': fileName
}, event.target["result"].split(',')[1]);
resolve(response);
}
await reader.readAsDataURL(xhr.response);
}
};
xhr.send();
} catch (error) {
reject();
console.log("error", error);
}
});
}
所以,我的问题是如何在不更新 ionic 和 cordova 的情况下解决这个问题?
对不起我的英语不好:D
提前致谢。
解决方案
在您index.html
尝试将脚本标签cordova.js
从标题移动到正文中,在build/polyfills.js
脚本标签下方。我的身体标签现在看起来像这样:
<body>
<!-- Ionic's root component and where the app will load -->
<ion-app></ion-app>
<!-- The polyfills js is generated during the build process -->
<script src="build/polyfills.js"></script>
<!-- cordova.js required for cordova apps (remove if not needed) -->
<script src="cordova.js"></script>
<!-- The vendor js is generated during the build process
It contains all of the dependencies in node_modules -->
<script src="build/vendor.js"></script>
<!-- The main bundle js is generated during the build process -->
<script src="build/main.js"></script>
</body>
根据这篇文章,显然这是 zone.js 的一个已知问题。
推荐阅读
- python - 如何打印任何网站内容?(使用类似我的代码的东西)
- expo - 要创建一个 Vue Native App,你需要 App.js 吗?
- laravel-5 - Laravel 广播事件私有
- jboss7.x - 无法在 Jboss 模块上正确注册 AWS-SDK
- c# - 使用反射调用泛型方法的辅助方法
- rasa-nlu - Rasa Chatbot:处理重复场景
- excel - 如果其他两个单元格匹配,则在另一个单元格的位置返回第三个单元格值
- c# - 如何将样式应用于 ASP.NET Core Razor 视图中的标记助手?
- python - 如何为字典中的相同键生成不同的值?
- reporting-services - 有没有办法从以 XML 模式呈现的 URL 报告数据?