1.开发环境配置代理解决跨域问题

首先在package.json平级文件创建一个vue.config.js

里面的内容是

module.exports = {
publicPath: './',
outputDir: 'dist', //build输出目录
assetsDir: 'assets', //静态资源目录(js, css, img)
lintOnSave: false, //是否开启eslint
devServer: {
open: true, //是否自动弹出浏览器页面
host: "localhost",
port: '8080',
https: false, //是否使用https协议
hotOnly: false, //是否开启热更新
proxy: {
'/api': {
target: 'https:/XXXX/XXX/api', //API服务器的地址
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
}
}
}
}

后面写请求的时候’/api/sendCaptcha’

2.生产环境nginx配置proxy解决打包后的跨域问题

如果用的宝塔的话,各个网站都是配置vhost,所以nginx的配置文件在,对应网站配置这里


注意地方是前台一定得是/api/xxx/xxx请求,后台配置的一定是http://xxxx/xxx/xxx/api/这个方式。

2 对 “vue4 vue-cli配置开发环境以及生产环境的跨越问题proxy代理”的想法;

  1. We therefore reviewed all available epidemiological literature published within the last 15 years to summarize the role of pretreatment serum albumin as an independent predictor of survival in cancer priligy walmart uk community profile casinoen17872086 Omg fortune casino promo codes, omg fortune free slots casino

发表评论

邮箱地址不会被公开。 必填项已用*标注

341 次浏览