当前位置: 首页 > Web前端 > vue.js

在vue中请求一个接口成功后,请求另一个接口

时间:2023-04-01 13:06:54 vue.js

相信大家在工作中也会遇到这种情况。成功请求一个接口后,你正在调用另一个接口。这时候如果按照常规的写法,在接口成功后的回调中写另一个接口的请求方法,那么就会出现第一个接口没有返回成功就调用第二个接口的情况。这是因为ajax是异步请求。那么就需要用到es6的语法了,下面是一个例子,希望对大家有所帮助getList(){axios.title:'glasses'}}).then(function(res){this.getOtherList;}).catch(function(error){console.log(error);});}//businessnext(){this.getOtherList().then(()=>{this.getList()})}getOtherList(){returnaxios.get('api/getOtherData.php',{params:{title:'glasses'}}).then(function(res){console.log(res.data.data)}).catch(function(error){console.log(error);});}getOtherList方法调用接口成功后,调用的接口获取列表