一、安装axios
$ npm install axios
二、在vue页面引入axios:
import axios from "axios"
三、在methods里定义发送http请求的函数:
getHello1() {
return axios.get('http://localhost:8097/hello1');
},
getHello2() {
return axios.get('http://localhost:8097/hello2');
},
四、在需要并发发送请求的函数里使用promise
Promise.all([this.getHello1(), this.getHello2()])
.then(function (results) {
console.log(results[0].data);
console.log(results[1].data);
});