vue-cli项目中想用window.open()打开本地的pdf,该怎么办

方法:

1.vue.config.js中配置module-->rules:
 const webpack = require('webpack')
module.exports = {
 
    configureWebpack: {
        plugins: [
            new webpack.ProvidePlugin({
                $: "jquery",
                jQuery: "jquery",
                "windows.jQuery": "jquery"
            })
        ],
        module: {
            rules: [{
                test: /\.pdf$/,
                use: [{

                    loader: 'url-loader',
                    options: {
                        limit: 2,
                        name: 'files/[name].[ext]'
                    }
                }]
            }]
        }
    }
}

2.打开时需要用require(文件路径) 进行打开,直接写路径打不开的。

window.open(require('../assets/pdf/dzs3.pdf'))

你可能感兴趣的:(vue-cli,javascript,vue.js)