uniapp 开发小程序——点击预览文件

1、问题描述:

点击文字-打开文件进行预览:
在这里插入图片描述

2、解决:

使用uni.openDocument 新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx。

<view class="formwork" @click="openFile()">
	点击查看公司授权书模板展示
</view>

<script>
	//打开文件
	openFile() {
      
      
		uni.downloadFile({
      
      
			url: this.hostUrl + '/static/index/prove.docx',  //文件的路径
			success: function(res) {
      
      
				var filePath = res.tempFilePath;
				uni.openDocument({
      
      
					filePath: filePath,
					showMenu: true,
					success: function(res) {
      
      
						console.log('打开文档成功');
					}
				});
			}
		});
	},
</script>

猜你喜欢

转载自blog.csdn.net/weixin_48596030/article/details/129985742
今日推荐