效果
代码 >>> 接收参数url 如(https://www.xxxx.xx/xxxx.word)
const openFile = (url) => {
uni.showLoading({
title: '加载中', // 提示的内容,默认“加载中”
mask: true, // 是否显示透明蒙层,防止触摸穿透,默认false
});
uni.downloadFile({
url: url,
success: function(res) {
const filePath = res.tempFilePath;
uni.hideLoading(); // 隐藏loading提示框
uni.openDocument({
filePath: filePath,
showMenu: true, //右上角是否有可以转发分享的功能
success: function() {
console.log('打开文档成功');
},
fail: function(err) {
console.error('打开文档失败', err);
uni.showToast({
title: '打开文档失败',
icon: 'none',
})
}
});
},
fail: function(err) {
console.error('下载文件失败', err);
}
});
}