代码语言:javascript复制
// 假如请求的接口是 http://192.168.1.100:8769/applications
let testAxios = axios.create({
baseURL: ""
})
testAxios.interceptors.request.use(function (config) {
config.headers.Accept = "application/json"
return config;
}, function (error) {
// Do something with request error
console.info("error: ");
console.info(error);
return Promise.reject(error);
});
testAxios.get("/applications/").then(res => {
console.log(res)
})
代码语言:javascript复制 // vue.config.js
devServer: {
open: false, // 项目运行后是否自动打开浏览器
//host: 'localhost',
host: '192.168.1.199',
//port: 8081,
https: false,
hotOnly: false, // 热更新
proxy: {
// 配置跨域
'/applications': {
target: 'http://192.168.1.100:8769',
wx: true,
changeOrigin: true,
pathRewrite: {
//'^/api': '/mock'
'^/applications': '/applications'
}
}
},
},
代码语言:javascript复制 // nginx中的配置
location~/applications/ {
proxy_pass http: //192.168.1.100:8769;
}