代码
后端返回的数据格式为
{
"success": true,
"data": [
{
"year": 2020,
"month": 1,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2020,
"month": 2,
"charge": 29000,
"discharge": 29000,
"temp": 36
},
{
"year": 2020,
"month": 3,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2020,
"month": 4,
"charge": 30000,
"discharge": 30000,
"temp": 36
},
{
"year": 2020,
"month": 5,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2020,
"month": 6,
"charge": 30000,
"discharge": 30000,
"temp": 36
},
{
"year": 2020,
"month": 7,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2020,
"month": 8,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2020,
"month": 9,
"charge": 30000,
"discharge": 30000,
"temp": 36
},
{
"year": 2020,
"month": 10,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2020,
"month": 11,
"charge": 30000,
"discharge": 30000,
"temp": 36
},
{
"year": 2020,
"month": 12,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2021,
"month": 1,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2021,
"month": 2,
"charge": 28000,
"discharge": 28000,
"temp": 36
},
{
"year": 2021,
"month": 3,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2021,
"month": 4,
"charge": 30000,
"discharge": 30000,
"temp": 36
},
{
"year": 2021,
"month": 5,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2021,
"month": 6,
"charge": 30000,
"discharge": 30000,
"temp": 36
},
{
"year": 2021,
"month": 7,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2021,
"month": 8,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2021,
"month": 9,
"charge": 30000,
"discharge": 30000,
"temp": 36
},
{
"year": 2021,
"month": 10,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2021,
"month": 11,
"charge": 30000,
"discharge": 30000,
"temp": 36
},
{
"year": 2021,
"month": 12,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2022,
"month": 1,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2022,
"month": 2,
"charge": 28000,
"discharge": 28000,
"temp": 36
},
{
"year": 2022,
"month": 3,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2022,
"month": 4,
"charge": 30000,
"discharge": 30000,
"temp": 36
},
{
"year": 2022,
"month": 5,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2022,
"month": 6,
"charge": 30000,
"discharge": 30000,
"temp": 36
},
{
"year": 2022,
"month": 7,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2022,
"month": 8,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2022,
"month": 9,
"charge": 30000,
"discharge": 30000,
"temp": 36
},
{
"year": 2022,
"month": 10,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2022,
"month": 11,
"charge": 30000,
"discharge": 30000,
"temp": 36
},
{
"year": 2022,
"month": 12,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2023,
"month": 1,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2023,
"month": 2,
"charge": 28000,
"discharge": 28000,
"temp": 36
},
{
"year": 2023,
"month": 3,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2023,
"month": 4,
"charge": 30000,
"discharge": 30000,
"temp": 36
},
{
"year": 2023,
"month": 5,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2023,
"month": 6,
"charge": 30000,
"discharge": 30000,
"temp": 36
},
{
"year": 2023,
"month": 7,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2023,
"month": 8,
"charge": 31000,
"discharge": 31000,
"temp": 36
},
{
"year": 2023,
"month": 9,
"charge": 20000,
"discharge": 20000,
"temp": 36
}
]
}
调用后端接口代码
getAsyncTempCurrentData().then((response) => {
console.log(response);
const years = response.data.map((item) => item.year+'年'+item.month+'月') ;
console.log(years);
init();
});
控制台输出years
[
"2020年1月",
"2020年2月",
"2020年3月",
"2020年4月",
"2020年5月",
"2020年6月",
"2020年7月",
"2020年8月",
"2020年9月",
"2020年10月",
"2020年11月",
"2020年12月",
"2021年1月",
"2021年2月",
"2021年3月",
"2021年4月",
"2021年5月",
"2021年6月",
"2021年7月",
"2021年8月",
"2021年9月",
"2021年10月",
"2021年11月",
"2021年12月",
"2022年1月",
"2022年2月",
"2022年3月",
"2022年4月",
"2022年5月",
"2022年6月",
"2022年7月",
"2022年8月",
"2022年9月",
"2022年10月",
"2022年11月",
"2022年12月",
"2023年1月",
"2023年2月",
"2023年3月",
"2023年4月",
"2023年5月",
"2023年6月",
"2023年7月",
"2023年8月",
"2023年9月",
"2023年10月"
]