Vue中如何实现axios的合并请求及slot使用技巧?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1980个文字,预计阅读时间需要8分钟。
javascript
一、使用axios并发请求
export default { data() { return {}; }, created() { function getMsg(res1, res2) { console.log(res1); console.log(res2); } this.$axios.all([ this, this.$axios.post('URL', 'key=value'), this.$axios.get('URL') ]).then(this.$axios.spread(getMsg)); }}一、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) }) } }
这样可以实现发送两个请求,只有所有都成功,才算是成功。只要有一个失败,就算是失败。
本文共计1980个文字,预计阅读时间需要8分钟。
javascript
一、使用axios并发请求
export default { data() { return {}; }, created() { function getMsg(res1, res2) { console.log(res1); console.log(res2); } this.$axios.all([ this, this.$axios.post('URL', 'key=value'), this.$axios.get('URL') ]).then(this.$axios.spread(getMsg)); }}一、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) }) } }
这样可以实现发送两个请求,只有所有都成功,才算是成功。只要有一个失败,就算是失败。

