有关axios另一种配置,给请求的接口加上时间
import axios from 'axios'
import qs from 'qs'
const install = function (Vue, config = {}) {
// $axios
Vue.prototype.$axios = (function () {
var axiosDeploy = axios.create({
headers: {
'Cache-Control': 'no-cache',
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
}
})
axiosDeploy.interceptors.request.use(function (config) {
config.transformRequest = [
function (data, header) {
return qs.stringify(data)
}
]
if (config.params) {
config.params._time = +new Date()
} else {
config.params = {
_time: +new Date()
}
}
return config
})
return axiosDeploy
})()
export default {
install
}