文档下载是很多app,尤其是企业应用中罕用的性能。应用APICloud开发app时,能够应用api.download办法实现下载;预览文档能够应用superFile 模块。superFile 模块封装了基于腾讯浏览服务TBS,应用X5Webkit内核,实现文件的展现性能,反对多种文件格式(PDF、Word、Execl、TXT、PPT)。
在我的项目中增加superFile模块:
而后编译自定义loader ,把自定义loader 安装包装置到手机上,而后就能够应用APICloud Studio3 wifi 同步性能,把代码同步到自定义loader 中进行调试。 参考教程: https://docs.apicloud.com/Dev-Guide/Custom_Loader
实例代码如下:
<template> <safe-area> <scroll-view class="main" scroll-y> <view><text onclick='this.downloadDoc_open'>下载并打开文档</text></view> </scroll-view> </safe-area></template><style>.main { width: 100%; height: 100%; background-color: #fff;}</style><script>export default { name: 'test', data() { return { } }, apiready() { }, methods: { downloadDoc_open() { api.download({ url: '', // 填写要下载文档的url savePath: 'fs://myapp/test.doc', report: true, cache: true, allowResume: true }, function (ret, err) { if (ret.state == 1) { //下载胜利 console.log(JSON.stringify(ret)); if (api.systemType == 'ios') { // ios 不须要初始化,间接open var superFile = api.require('superFile'); superFile.open({ path: ret.savePath, }) } if (api.systemType == 'android') { console.log(2); var superFile = api.require('superFile'); superFile.init(function (ret) { if (ret.eventType == 'onViewInitFinished') { superFile.open({ path: ret.savePath }) } }); } } }); } }}</script>