uniapp H5预览excle、pdf、word等文件
1.代码previewFile() {uni.showLoading({title: '加载中'})uni.downloadFile({url: "https://..../gwy.xls", //后端返回的文件地址// filePath: wx.env.USER_DATA_PATH + '/gwy.xls',// filePath: wx.env.USER_DATA_PATH + '/' + i
·
1.代码
previewFile() {
uni.showLoading({
title: '加载中'
})
uni.downloadFile({
url: "https://..../gwy.xls", //后端返回的文件地址
// filePath: wx.env.USER_DATA_PATH + '/gwy.xls',
// filePath: wx.env.USER_DATA_PATH + '/' + item.name + '.' + item.value.split('.')[item.value.split('.').length - 1],
success: function(res) {
if (res.statusCode === 200) {
uni.openDocument({
showMenu: true,
filePath: res.tempFilePath,
success: function(res) {
console.log(res, '打开文件成功')
},
fail: (err) => {
uni.showToast({
title: '打开文件失败请重试',
icon: 'none'
})
}
})
} else {
uni.showToast({
title: '打开文件失败请重试',
icon: 'none'
})
}
uni.hideLoading()
},
fail: (err) => {
uni.hideLoading()
uni.showToast({
title: '加载失败请重试',
icon: "none"
})
}
})
}
更多推荐
已为社区贡献23条内容
所有评论(0)