Document download is a commonly used function in many apps, especially enterprise applications. When developing an app with APICloud, you can use the api.download method to download it; you can use the superFile module to preview documents. The superFile module encapsulates TBS based on Tencent browsing service, uses the X5Webkit kernel, realizes the display function of files, and supports multiple file formats (PDF, Word, Excell, TXT, PPT).
Add the superFile module to the project:
Then compile the custom loader, install the custom loader installation package on the mobile phone, and then use the APICloud Studio3 wifi synchronization function to synchronize the code to the custom loader for debugging. Reference tutorial: https://docs.apicloud.com/Dev-Guide/Custom_Loader
The example code is as follows:
<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>
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。