微信小程序原生预览文件
function previewFile(value) {const fileExtName = `${value.ext}`;const randFile = new Date().getTime() + fileExtName;uni.showLoading({title: '加载中...'})wx.downloadFile({url: value.url, filePath: wx.env.USER_DATA_PATH + '/' + randFile, success: function(res) {let filePath = res.filePath; let fileType = value.ext.substring((1));wx.openDocument({filePath: filePath,fileType: fileType,success: function() {},fail: function() {}});uni.hideLoading();},fail: function() {}});
}
uniapp预览电子文件
function previewFile(value) {let fileType = value.ext.substring((1)); uni.showLoading({title: '加载中...'})uni.downloadFile({url: value.url,success: function(res) {let filePath = res.tempFilePath;uni.openDocument({filePath: filePath,fileType,success: function(res) {}});uni.hideLoading();}});
}