前端代碼:
data() {
return {
listQuery: {
date: [],
}
}
},
//查詢列表信息
getList() {
if (this.listQuery.date == null || this.listQuery.date.length != 2) {
this.$message.warning("請選擇時間后查詢")
return
}
this.listLoading = true
console.log(this.listQuery) // {date:["2020-10-06","2020-11-06"]}
accDrainageQuery.getList(this.listQuery).then(res => {
this.list = res.data
this.listLoading = false
this.$refs.dataChart.list = res.data
this.$refs.dataChart.formatdata()
}).catch(err => {
console.log(err)
})
},
后端代碼:
后端用String接收,
注意:前端axios傳遞一個包含數組的對象{date:["2020-10-06","2020-11-06"]}到后台,會自動轉換成字符串2020-10-06,2020-11-06,我們再用String split[] = date.split(",")分割成字符串數組。
@GetMapping("/list") public Result getList(String date) { return officialAccoutService.getList(date); }
String split[] = date.split(",");
后端用List接收,
@GetMapping("/list") public Result getList(@RequestParam List date) { }