axios 设置请求超时时间

import axios from 'axios';

axios.defaults.timeout = 500

axios.interceptors.response.use(response => {
  return response
}, err => {
    if(err.message == 'timeout of 5000ms exceeded'){
        return {code : 10,message:'请求超时'}
    }else{
        return {code :500, message:'网络连接失败,请稍后重试'}
    }
})


this.$store.dispatch(formData).then(res=>{
    if(res.code == 200){
        console.log('请求成功')
    }
}).catch(err=>{
    alert(err.message)
})

 

你可能感兴趣的:(vue,React)