axios中post请求调后台接口,类型是application/json
先引入axios
import axios from "axios";
将更新数据的方法放在created中,以及获取开始时间、结束时间
this.callTime[0] = this.startDate;
this.callTime[1] = this.endDate;
this.getTimeList(); //调用方法查询指定时间段内的数据
下面是axios的使用,携带的数据是startDate和endDate
getTimeList() {
var data = JSON.stringify({
startDate: this.callTime[0],
endDate: this.callTime[1],
});
var config = {
method: "post",
url: "http://*.*.*.*:8080/statistics/getDataStatistics",
headers: {
"Content-Type": "application/json",
},
data: data,
};
axios(config)
.then((response) => {
const {
totalUser,
totalCallTime,
totalCallNumber,
avgCallTime,
yesterdayNewUser,
pendingReview,
} = response.data;
(this.toTotalData.totalUser = totalUser),
(this.toTotalData.totalCallTime = totalCallTime),
(this.toTotalData.totalCallNumber = totalCallNumber),
(this.toTotalData.avgCallTime = avgCallTime),
(this.toTotalData.yesterdayNewUser = yesterdayNewUser),
(this.toTotalData.pendingReview = pendingReview);
})
.catch((error) => {
console.log(error);
});
// console.log(this.callTime);
},
参数在data中声明
data() {
return {
lineChartData: lineChartData.totalUsers,
toTotalData: {
totalUser: 1,
totalCallTime: 1,
totalCallNumber: 1,
avgCallTime: 1,
yesterdayNewUser: 1,
pendingReview: 1,
},
callTime: ["2021-11-09", "2021-11-09"],
};
},