调用接口未接通时,可以用Promise.resolve()或者Promise.reject()模拟成功和失败的返回
eg:正常写法
export function getData() { return request({ method:'get', url:'xxx' }) }
模拟成功
export function getData (){ return resolve({ code:'200', msg:'调用成功', data:{} }) }
模拟失败
export function getData (){ return reject("调用失败") }
调用接口:
getData().then( res =>{ console.log(res.msg) //调用成功 }) .catch(err => { console.log(err)//调用失败 })
then里面是模拟成功的返回,catch是模拟失败的返回
标签:function,调用,未通,接口,export,getData,模拟 From: https://www.cnblogs.com/zengyu123/p/17695775.html