vue中 vue-cli3 跨域配置 在 vue.config.js中
const apiIP = 'http://192.168.1.111:8082'
module.exports = {
...
...
devServer: {
port: "8080",
open: true,
hot: true,
disableHostCheck: true,
clientLogLevel: "warning",
overlay: {
warnings: false,
errors: true
}
proxy: {//非开发环境,注释(后端本地ip跨域)
'/dev-api': {
target: apiIP,
secure: false,
changeOrigin: true,
pathRewrite: {
'^/dev-api': ''
}
}
}
}
}
遇到dev-api 开始的接口 就代理到对应的 http://192.168.1.111:8082 服务上
然后对axios 进行处理
const FFBaseURL = '/dev-api'
const requestNew = (data) => {
return request({
...data,
...{
baseURL: FFBaseURL
}
})
}
export const getEventAction = () => {
return requestNew({
url: '/analysis/queryEventRule',
method: 'post'
})
}
要是上面的看不懂
export const getEventAction = () => {
return request({
url: '/dev-api/analysis/queryEventRule',
method: 'post'
})
}