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>
