📅  最后修改于: 2022-03-11 15:00:44.089000             🧑  作者: Mango
interface MyApiData {
name: string;
}
class Example {
async getData(foo: string, bar: string) {
let response = await fetch(
'/LostEnergyCalculation/GetGridAndPieChartsData',
{
method: 'post',
headers:new Headers({
'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
}),
body: `foo=${foo}&bar=${bar}`
});
let data: MyApiData = await response.json();
return data;
}
}
const example = new Example();
example.getData('foovalue', 'barvalue').then((data) => {
alert(data.name);
});