当我们遇到请求后台接口遇到 Access-Control-Allow-Origin
时,那说明跨域了
Vue中解决跨域常用方法:
1、在vue.config.js
中设置如下代码片段
module.exports = {
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: { // 配置跨域
'/api':{
target:'https://www.paozha.net', //请求后台接口
changeOrigin:true, // 允许跨域
pathRewrite:{
'^/api' : 'https://www.paozha.net' //请求后台接口
}
}
},
}
配置完毕一定要重启脚手架,就是前端server