2
2
* @Author : zhanghan
3
3
* @Date : 2023-01-10 14:28 :29
4
4
* @LastEditors : zhanghan
5
- * @LastEditTime : 2023-01-11 11: 49 : 50
5
+ * @LastEditTime : 2023-01-11 16: 20 : 52
6
6
* @Descripttion : 快速上手
7
7
-->
8
8
<template>
24
24
>
25
25
file-viewer
26
26
</a>
27
+ 。
27
28
<br />
28
- (必须包含file-viewer文件夹,不可重命名,若需要重命名可下载源码重新修改构建)
29
29
</h4>
30
- <h4>2、将下载后的文件夹放在项目public文件夹中作为外部公共资源使用</h4>
30
+ <h4>
31
+ 2、将下载后的file-viewer文件夹整个放在项目公共文件夹中作为外部公共资源使用。
32
+ <br />
33
+ (以vue-cli为例,放置在项目public文件夹下;其他框架自行选择合适的公共路径放置)
34
+ </h4>
31
35
<h3>注意事项:</h3>
32
- <h4>* 本项目示例链接随时失效,请勿直接用于生产环境</h4>
33
- <h4>* 被浏览的文件链接必须同源或本身支持跨域访问</h4>
36
+ <h4>* 本项目示例链接随时失效,请勿直接用于生产环境。</h4>
37
+ <h4>* 被浏览的文件链接必须同源或本身支持跨域访问。</h4>
38
+ <h4>
39
+ *
40
+ 若发布生产的项目不在服务器域名根目录,记得配置打包的前缀路径,打包后资源才能被正常引用。(以vue-cli为例,配置
41
+ <code>vue.config.js</code>
42
+ 的
43
+ <code>publicPath: './'</code>
44
+ ; 其他框架请自行选择合适的配置文件进行配置)
45
+ </h4>
34
46
<br />
35
47
36
- <h4 >一般url传入使用</h4 >
48
+ <h3 >一般url传入使用</h3 >
37
49
<section class="demo">
38
50
<div
39
51
class="section-content swiper"
40
52
style="height: 500px;overflow: hidden;"
41
53
>
42
54
<iframe
43
- src="/file-viewer/index.html?fileUrl=https://home.sharecorner.top/fileTest/pdf.pdf"
55
+ src=". /file-viewer/index.html?fileUrl=https://home.sharecorner.top/fileTest/pdf.pdf"
44
56
scrolling="auto"
45
57
style="border:0;height: 100%;width:100%"
46
58
/>
54
66
</Collapse>
55
67
</section>
56
68
57
- <h4>支持二进制文件流消息推送</h4>
69
+ <h3>支持二进制文件流消息推送</h3>
70
+ <h3>注意事项:</h3>
71
+ <h4>
72
+ *
73
+ 若为node环境,且发布生产的项目不在服务器域名根目录,这将导致生产和开发环境的引用路径不一致(由于动态赋值的路径只会被编译器原样解析,需要特别注意通过配置打包的前缀路径也不会对此次生效,例如
74
+ <code>vue-cli</code>
75
+ 的
76
+ <code>publicPath</code>
77
+ ),可通过
78
+ <code>process.env.NODE_ENV</code>
79
+ 进行手动判断。
80
+ </h4>
81
+ <h4>* 若为浏览器环境,若有需要可在前面配置统一前缀路径即可。</h4>
58
82
<section class="demo">
59
83
<div
60
84
class="section-content swiper"
@@ -101,7 +125,7 @@ import { config } from '../config'
101
125
102
126
const iframeSnippet = `
103
127
<iframe
104
- src="/file-viewer/index.html?fileUrl=https://home.sharecorner.top/fileTest/pdf.pdf"
128
+ src=". /file-viewer/index.html?fileUrl=https://home.sharecorner.top/fileTest/pdf.pdf"
105
129
scrolling="auto"
106
130
style="border:0;height: 100%;width:100%"
107
131
/>
@@ -119,7 +143,12 @@ export default {
119
143
context: {
120
144
// 查看器的地址
121
145
// 自己项目内部署需要将编译后的产物file-viewer放在public文件夹中使用,编译后的产物需要下载,下载链接在文档上
122
- origin: location.origin + '/file-viewer/index.html',
146
+ // 若为node环境,且发布生产的项目不在服务器域名根目录,这将导致生产和开发环境的引用路径不一致(由于动态赋值的路径只会被编译器原样解析,需要特别注意通过配置打包的前缀路径也不会对此次生效,例如vue-cli的publicPath),可通过process.env.NODE_ENV进行手动判断
147
+ // origin: location.origin + process.env.NODE_ENV === 'production'
148
+ ? '/你的前缀路径(没有可去除)/file-viewer/index.html'
149
+ : '/file-viewer/index.html',
150
+ // 若为浏览器环境,若有需要可在/file-viewer前面配置统一前缀路径即可
151
+ origin: location.origin + '/你的前缀路径(没有可去除)/file-viewer/index.html',
123
152
// 目标frame
124
153
frame: null,
125
154
// 浏览的文件url
@@ -221,7 +250,12 @@ export default {
221
250
context: {
222
251
// 查看器的地址
223
252
// 自己项目内部署需要将编译后的产物file-viewer放在public文件夹中使用,编译后的产物需要下载,下载链接在文档上
224
- origin: location.origin + '/file-viewer/index.html',
253
+ // 若为node环境,且发布生产的项目不在服务器域名根目录,这将导致生产和开发环境的引用路径不一致(由于动态赋值的路径只会被编译器原样解析,需要特别注意通过配置打包的前缀路径也不会对此次生效,例如vue-cli的publicPath),可通过process.env.NODE_ENV进行手动判断
254
+ origin:
255
+ location.origin +
256
+ (process.env.NODE_ENV === 'production'
257
+ ? '/file-viewer-doc/file-viewer/index.html'
258
+ : '/file-viewer/index.html'),
225
259
// 目标frame
226
260
frame: null,
227
261
// 浏览的文件url
@@ -231,6 +265,7 @@ export default {
231
265
},
232
266
mounted() {
233
267
this.loadFromUrl()
268
+ console.log('process.env.NODE_ENV', process.env.NODE_ENV)
234
269
},
235
270
methods: {
236
271
// 获取文件二进制流
0 commit comments