vue中axios设置timeout超时

$.ajax({
  url: '接口地址',
  type:'get',		//请求方式get或post
  data:{},			//请求所传的参数
  dataType: 'json',	//返回的数据格式
  timeout: 4000,	//设置时间超时,单位毫秒
  success: function(result) {
  console.log('OK')
  },
  error: console.log('error')
 })

axios.post(		//请求方式
url,			//接口地址
params,			//传递参数
{timeout: 1000 * 60 * 2})		//设置超时,单位毫秒
.then(function(res){
    console.log(res);
}).catch((error) => {
    console.log('error')
})

发布了209 篇原创文章 · 获赞 38 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/weixin_43953710/article/details/103701933