https://blog.csdn.net/wh_xmy/article/details/87705840
main.js
import axios from 'axios'
Vue.prototype.$axios = axios
axios.defaults.baseURL = '/api'
config index.js
proxyTable: {
//後加的
'/api': {
target:'http://123.57.103.198', // 你請求的第三方接口
changeOrigin:true, // 在本地會創建一個虛擬服務端,然後發送請求的數據,並同時接收請求的數據,這樣服務端和服務端進行數據的交互就不會有跨域問題
pathRewrite:{ // 路徑重寫,
'^/api': '' // 替換target中的請求地址,也就是說以後你在請求http://api.douban.com/v2/XXXXX這個地址的時候直接寫成/api即可。
}
},
//後加的
},
// proxyTable:{
// './': {
// target: 'http://www.xxx.cn/api', //你要訪問的服務器域名
// changeOrigin: true, //允許跨域
// pathRewrite: {
// '^/': ''
// }
// }
// },
// CSS Sourcemaps off by default because relative paths are "buggy"
// with this option, according to the CSS-Loader README
// (https://github.com/webpack/css-loader#sourcemaps)
// In our experience, they generally work as expected,
// just be aware of this issue when enabling this option.
cssSourceMap: false
}