import Vue from "vue"
import axios from "axios"
import VueAxios from "vue-axios"
import Qs from "qs"
Vue.prototype.baseUrl = "/api"
// 环境的切换
if (process.env.NODE_ENV == 'development') {
Vue.prototype.baseUrl = "http://localhost:8000";}
else if (process.env.NODE_ENV == 'debug') {
Vue.prototype.baseUrl = "http://localhost:8000";
}
else if (process.env.NODE_ENV == 'production') {
Vue.prototype.baseUrl = "http://localhost:8000";
}
Vue.prototype.$get = function (api, data) {
if (data === undefined) {
data = {}
}
var ox = axios.get(this.baseUrl + api, { params: data })
return ox
}
Vue.prototype.$post = function (api, data) {
data = Qs.stringify(data)
var ox = axios.post(this.baseUrl + api, data)
return ox
}
Vue.use(VueAxios, axios)
Axios请求的封装
最新推荐文章于 2024-07-18 13:56:07 发布