VUE—all并发请求
<script>
import axios from 'axios'
export default {
name: "all",
methods: {
getUrl () {
return axios.get('https://www.easy-mock.com/mock/5d41580a1a802c0d5e53dcc2/example/aa')
},
postUrl () {
return axios.post('https://www.easy-mock.com/mock/5d41580a1a802c0d5e53dcc2/example/bb')
},
allUrl () {
axios.all([this.getUrl(), this.postUrl()])
// 注意里面是一个数组,不要出错
.then(axios.spread((res1, res2) => {
// 注意里面是箭头函数,容易出错
// res1是getUrl获取的, res2是postUrl获取的
console.log(res1.data, res2.data)
}))
}
},
created () {
this.allUrl()
}
}
</script>
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/1c0b8fc8a52c57aa7173540a4406b954.png)