Vue   发布时间:2022-04-21  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了vue打包使用Nginx代理解决跨域问题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

vue 在开发环境,涉及跨域,就在本地配置了代理,但是部署到服务器上,就不行了。

解决方法有一下几种

  • 服务器端配置CORS
  • Nginx反向代理,和访问本地服务器是一样的
  • 可以修改成正式线上的地址,再build

推荐

vue index.js文件源码

subdirectory: 'static',assetsPublicPath: '/',changeOrigin: true,proxyTable: {
'/api': {
target: 'https://api.it120.cc/fengyu',changeOrigin:true,pathRewrite: {
'^/api': ''
}
},'/book': {
target: 'http://api.zhuishushenqi.com/',pathRewrite: {
'^/book': ''
}
},},// VarIoUs Dev Server settings
host: 'localhost',// can be overwritten by process.env.HOST
port: 8080,// can be overwritten by process.env.PORT,if port is in use,a free one will be determined
autoOpenBrowser: false,errorOverlay: true,notifyOnErrors: true,poll: false,// https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
/**
* Source Maps
*/
// https://webpack.js.org/configuration/devtool/#development
devtool: 'eval-source-map',// If you have problems debugging vue-files in devtools,// set this to false - it *may* help
// https://vue-loader.vuejs.org/en/options.html#cachebusting
cacheBusting: true,// CSS Sourcemaps off by default because relative paths are "buggy"
// with this option,according to the css-Loader README
// (https://github.com/webpack/css-loader#sourcemaps)
// In our experience,they generally work as expected,// just be aware of this issue when enabling this option.
cssSourceMap: false,build: {
// Template for index.html
index: path.resolve(__dirname,'../dist/index.html'),// Paths
assetsRoot: path.resolve(__dirname,'../dist'),assetssubdirectory: './static',assetsPublicPath: './',/**
* Source Maps
*/
productionSourceMap: true,// https://webpack.js.org/configuration/devtool/#production
devtool: '#source-map',// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`,make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,productionGzipExtensions: ['js','css'],// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report
}
}

大佬总结

以上是大佬教程为你收集整理的vue打包使用Nginx代理解决跨域问题全部内容,希望文章能够帮你解决vue打包使用Nginx代理解决跨域问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: