赞
踩
- async openPdf() {
- const {data: result} = await uni.$http.get('/api/user/add_pdf', {id: this.enrollId})
- if (result.state == 1) {
- // 此为文件名称,名称前需带/,如(/文档.pdf)
- let fileName = result.url.slice(4)
- wx.downloadFile({
- url: this.baseUrl + result.url,
- filePath: wx.env.USER_DATA_PATH + fileName,
- success(res) {
- const filePath = res.filePath || res.tempFilePath
- //下载完成自动打开文件
- wx.openDocument({
- showMenu: true,
- filePath,
- fileType: 'pdf',
- success: function (res) {
- console.log('打开文档成功')
- }
- })
- },
- fail(err) {
- console.log('打开文档失败', err)
- }
- })
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。