步驟如下:
1、下載需要準備的工具文件包
2、將其解壓到/static/pdf文件夾下,如圖:
3、創建在線查看文件的頁面:
<template><view><web-view :src="path"></web-view></view>
</template><script>
export default {data() {return {//你的pdf鏈接,鏈接以https://開頭的可在線訪問的urlfileUrl: "",//pdf.htm所在路徑viewerUrl: '/static/pdf/-pdf--master/hybrid/pdf.html',path: ""};},onLoad(options) {//options.url 在線預覽的文件的地址this.fileUrl = options.url;},onShow() {//進行拼接即可this.path = `${this.viewerUrl}?url=${this.fileUrl}`}
}
</script><style>
</style>
4、準備好這些之后,只要保證你的文件地址能夠訪問,即可在線預覽文件,如圖: