赞
踩
方法一:直接将图片放在static目录下,在index.html中直接引用
1)下载pdfjs,将文件夹解压后放在static目录下。
2)将view.js中的跨域代码进行注释,不然会报错:
3)使用代码如下:
<template> <!-- 预览pdf --> <view> <web-view :webview-styles="webviewStyles" :src="url"></web-view> </view> </template> <script> export default { data() { return { webviewStyles: { progress: { color: '#298DF8' } }, url: "", // 最终显示在web-view中的路径 viewerUrl: '/static/pdf/web/viewer.html', // pdf.js的viewer.htm所在路径 fileUrl: 'https://1.2.com/' // 要访问的pdf的路径 } }, onLoad(options) { let onlineUrl = this.fileUrl+options.url console.log('onlineUrl',onlineUrl) // h5,使用h5访问的时候记得跨域 // #ifdef H5 this.url = `${this.viewerUrl}?file=${encodeURIComponent(onlineUrl)}`; // #endif // 判断是手机系统:安卓,使用pdf.js // #ifdef APP-PLUS if(plus.os.name === 'Android') { this.url = `${this.viewerUrl}?file=${encodeURIComponent(onlineUrl)}`; } // ios,直接访问pdf所在路径 else { this.url = encodeURIComponent(onlineUrl); } // #endif }, } </script>
在项目根目录下新建vue.config.js文件,文件中代码写入
// vue.config.js
module.exports = {
productionSourceMap: false, // 生产打包时不输出map文件,增加打包速度
configureWebpack: config => {
if (process.env.NODE_ENV === 'production') {
config.optimization.minimizer[0].options.terserOptions.compress.warnings = false
config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true
config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = ['console.log']
}
}
}
stylus编译
、scss/sass编译
、easy-git
、Vue/Vuex/Vue Router代码块
、Javascript代码块
、es6编译
等
function onAccessTokenFetched() {
subscribers.forEach((callback) => {
callback();
})
subscribers = [];
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。