1.Vue+axios
//main.js
import axios from 'axios'
Vue.prototype.$ajax= axios
//xxx.vue
this.$ajax.get("/car/getAllCar").then(res=>(
console.log(res.data)
))
2.解决跨域问题
1.在devServer中加入proxy
//vue.config.js
proxy: {
[process.env.VUE_APP_BASE_API]: {
target: 'http://127.0.0.1:8080',
changeOrigin: true,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
}
}
},
2.在.env.development中将VUE_APP_BASE_API置空
# just a flag
ENV = 'development'
# base api
VUE_APP_BASE_API = ''
完美解决