/** * 获取所有路口数据 */ function A() { return axios.post(contextPath+"/book/getList"); }
//获取协调路径中每个信号机的特征参数 function B(acsIdList) { return axios.post(contextPath+"/user/getUserById",{ id: id }); }
axios.all([A(),B()]) .then(axios.spread(function(data1,data2){ if(!(data1.status==200&&data2.status==200)) return; data1 =data1.data; data2 =data2.data; //TODO })) .catch(function (error) { console.log(error); });
如果后台得不到参数或者数据中文乱码,那么添加一下设置:
/** * Created by huangshengtao on 2018-8-21. */ axios.defaults.headers = { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8" } axios.defaults.transformRequest = [function (data) { var newData = ""; for (var k in data) { newData += encodeURIComponent(k) + '=' + encodeURIComponent(data[k]) + '&' } return newData }]