1.给需要看的文件一个点击事件
<view wx:for="{
{fileList}}" bindtap="viewFile">{
{item.fileName}}</view>
2.引入自己写的公共方法
import {downloadFile} from '../../../utils/viewFile'
3.以下就是自己写的方法
export function downloadFile (url,type) {
wx.showLoading({
title: '加载中...',
});
wx.downloadFile({//下载对应文件
url: url,
success: function (res) {
console.log(res)
let filePath = res.tempFilePath;//文件路径
wx.openDocument({
filePath: filePath, // 装载对应文件的路径
fileType: type, // 指定打开的文件类型
showMenu: true, // 右上角的菜单转发分享操作
success: function (res) {
wx.hideLoading();
console.log("打开成功");
},
fail: function (res) {
console.log(res);
wx.hideLoading();
wx.showToast({
title: '打开失败',
icon: &#