Vue中如何使用axios进行合并请求并巧妙运用slot实现复用?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1982个文字,预计阅读时间需要8分钟。
javascript
一、使用axios并发请求
导出默认模块function fetchData() { return { data: {}, created() { this.$axios.all([ this.$axios.post('URL', 'key=value'), this.$axios.get('URL') ]).then(this.$axios.spread((res1, res2)=> { console.log(res1); console.log(res2); })); } };}一、axios合并请求
export default { data(){ return {} }, created(){ function getMsg(res1,res2){ console.log(res1) console.log(res2) } this.$axios.all([ this,axios.post('URL','key=value'), this.axios.get('URL') ]) .then(this.$axios.spread(getMsg)) //分发响应 .catch(err => { console.log(err) }) } }
这样可以实现发送两个请求,只有所有都成功,才算是成功。只要有一个失败,就算是失败。
本文共计1982个文字,预计阅读时间需要8分钟。
javascript
一、使用axios并发请求
导出默认模块function fetchData() { return { data: {}, created() { this.$axios.all([ this.$axios.post('URL', 'key=value'), this.$axios.get('URL') ]).then(this.$axios.spread((res1, res2)=> { console.log(res1); console.log(res2); })); } };}一、axios合并请求
export default { data(){ return {} }, created(){ function getMsg(res1,res2){ console.log(res1) console.log(res2) } this.$axios.all([ this,axios.post('URL','key=value'), this.axios.get('URL') ]) .then(this.$axios.spread(getMsg)) //分发响应 .catch(err => { console.log(err) }) } }
这样可以实现发送两个请求,只有所有都成功,才算是成功。只要有一个失败,就算是失败。

