当前位置:   article > 正文

json请求 post vue_vue发送get post jsonp请求

vue $jsonp 如何post

1. 使用 vue-resource 发送get、 post、 jsonp请求官方已不再维护使用 vue-resource 发送 get 请求this.$http.get('/someUrl').then(response => {

// get body data

console.log(response.body)

}, error => {

// error callback

})使用 vue-resource 发送 post 请求this.$http.post('/someUrl', {body}, {config}).then(response => {

// 默认发起的 post 请求,默认没有表单格式,所以有的服务器处理不了

// 通过查阅文档发现,通过 post 方法的第三个参数,{ emulateJSON:true }设置提交的内容为普通表单数据格式

console.log(response.body)

}, error => {

// error callback

})使用 vue-resource 发送 jsonp 请求this.$http.jsonp('/someUrl', {config}).then(response => {

console.log(response.body)

}, error => {

// error callback

})

2.axios请求超时的处理,超时重新发送// 重发次数

axios.defaults.retry = 10

// 间隔时间

axios.defaults.retryDelay = 1000

axios.interceptors.response.use(undefined, function axiosRetryInterceptor (err) {

var config = err.config

if (!config || !config.retry) return Promise.reject(err)

config.__retryCount = config.__retryCount || 0

if (config.__retryCount >= config.retry) {

return Promise.reject(err)

}

config.__retryCount += 1

var backoff = new Promise(function (resolve) {

setTimeout(function () {

resolve()

}, config.retryDelay || 1)

})

return backoff.then(function () {

return axios(config)

})

})

3.axios设置请求超时,弹窗提示axios.defaults.timeout = 10 * 1000

axios.interceptors.response.use(undefined, error => {

var originalRequest = error.config

if (error.code === 'ECONNABORTED' && error.message.indexOf('timeout') !== -1 && !originalRequest._retry) {

MessageBox.alert('网络请求超时,请稍后进行尝试', '移动OA提示')

}

})

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/279995
推荐阅读
相关标签
  

闽ICP备14008679号