import qs from 'qs' // 解决post请求参数不对的问题
// http request 拦截器
axios.interceptors.request.use(
config => {
config.data = JSON.stringify(config.data)
config.headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
return config
}, error => {
return Promise.reject(error)
}
)
/**
* 封装post请求
* @param url
* @param data
* @returns {Promise}
*/
export function post (url, data = {}) {
return new Promise((resolve, reject) => {
axios.post(url, qs.stringify(data))
.then(response => {
resolve(response.data)
}, err => {
reject(err)
})
})
}
转载于 https://blog.csdn.net/strong90/article/details/100893840