vue-cli2!!! 的接口环境配置,注意是cli2!!!!
有好几个后端,前缀地址都不相同如下, 有什么办法让它们切换不用重新编译吗????
axios 是单独抽离配置的:
回答:
proxy参考如下做法
proxy: { '/api': {
target: process.env.VUE_APP_BASE_API,
changeOrigin: true,
pathRewrite: {
'^/api/': '/'
}
},
'/local': {
target: 'http://127.0.0.1:3000/api',
changeOrigin: true,
pathRewrite: {
'^/local/': '/'
}
},
'/other': {
target: 'http://192.168.50.77:9999/',
changeOrigin: true,
pathRewrite: {
'^/other/': '/'
}
}
},
}
axios请求配置时
const service = axios.create({ baseURL: '/api', // api base_url 这里用api/local/other切换就行了
timeout: 10000,
headers: { 'Access-Control-Allow-Origin': '*' }
})
以上是 vue-cli2!!! 的接口环境配置,注意是cli2!!!! 的全部内容, 来源链接: utcz.com/p/935858.html