目前写的是一个兼容H5与小程序的项目。大多数内容还是可以比较完美的兼容的。但是到了下载文件这里就出了点问题。
uni.downloadFile虽然是可以兼容小程序和H5,但是uni.saveFile是不支持的。
这里就把两端分开写了。
HTML
<!-- #ifdef H5 -->
<a class="table-btn" href="http://xxxxxxxxxx" target='_blank'>下载入口</a>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<view class="table-btn" @click="downLoad(item.id)">下载入口</view>
<!-- #endif -->
JS
/**
* 下载到本地
*/
downLoad: function(id) {
uni.downloadFile({
url: 'http://xxxxxxxxxx?id=' + id, //仅为示例,并非真实的资源
success: (e) => {
if (e.statusCode === 200) {
let tempFilePaths = e.tempFi