大家好,最近工作时遇见了个需求,要求用户在小程序中实现文件预览功能,查阅uniapp官网后,找到了方法如何去实现这个功能,话不多说,上代码。
<template>
<view @click="previewDoc">预览</view>
</template>
const previewDoc = () => {
uni.downloadFile({
url: fileUrl, //要在微信公众平台配置域名 https://www.xxxx.com.cn:xxxx
success: function (res) {
console.log('res', res);
var filePath = res.tempFilePath;
uni.openDocument({
filePath: encodeURI(filePath),
showMenu: true,
success: function (res) {
console.log('打开文档成功', res);
}
});
}
});
};
要记得在微信公众平台配置域名 https://www.xxxx.com.cn:xxxx
有问题
有问题,请大家及时评论指出,加以改正!