📜  等待获取参数 - 任何代码示例

📅  最后修改于: 2022-03-11 15:00:44.089000             🧑  作者: Mango

代码示例1
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);
});