import axios from ‘axios‘
Vue.prototype.$axios=axios;
module.exports = {
devServer: {
open: true,
host: ‘localhost‘,
port: 8080,
https: false,
hotOnly: false,
proxy: {
// 配置跨域
‘/api‘: {
target: ‘http://192.168.1.105:8081‘,//后端接口地址
ws: true,
changOrigin: true,
pathRewrite: {
‘^/api‘: ‘‘
}
}
},
before: app => {}
}
};
this.$axios.get(‘/api/test‘)
//最后请求的地址会是http://192.168.1.105:8081/hello,但我测试还是localhost,无效
import axios from ‘axios‘
Vue.prototype.$axios=axios;
module.exports = {
dev: {
// Paths
assetsSubDirectory: ‘static‘,
assetsPublicPath: ‘/‘,
proxyTable: {
‘/‘: {
target: ‘http://192.168.1.105:8081‘,//后端接口地址
changOrigin: true,
pathRewrite: {
‘^/‘: ‘/‘
}
}
}
}
}
this.$axios.get(‘/hello‘).then(res=>{
console.log(res);
})
原文:https://www.cnblogs.com/lxy3/p/14585185.html