gpt4 book ai didi

javascript - 如何在 typescript 中使用 isomorphic-fetch

转载 作者:行者123 更新时间:2023-11-30 15:09:32 26 4
gpt4 key购买 nike

我收到错误@types/isomorphic-fetch has no default export fetch

import fetch from 'isomorphic-fetch';

export const AUTH_FAIL = "AUTH_FAIL"
export const ERROR_FETCH = "EROR_FETCH";
export const SUCCESS_FETCH = "SUCESS_FETCH";
export const START_FETCH = "START_FETCH";

export function start_fetch(){
return function(dispatch: any){
return fetch("http://localhost:8000/api/data")
.then(
response => response.json()
)
}
}

感谢您的帮助。

最佳答案

我能够通过像这样导入库来使其工作:

import 'isomorphic-fetch';

虽然在那之前我必须填充 ES6 Promises。例如:

import * as e6p from "es6-promise";
(e6p as any).polyfill();

关于javascript - 如何在 typescript 中使用 isomorphic-fetch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45293599/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com