3

尝试使用时window.FormData出现以下错误:

The name 'FormData' does not exist in the current scope

FileReader 也是如此

4

2 回答 2

6

添加dom到项目中的lib数组中tsconfig.json

{
  "compilerOptions": {
    ...
    "lib": ["es2018", "dom"], // add `dom` to the array
    ...
  }
}
于 2019-02-20T09:38:01.690 回答
1

您可以使用以下方法检查功能是否存在:

if (window.FormData) {
    alert('Yes');
}

这依赖于虚假检查 - 如果您想明确,请使用。

if (typeof FormData !== 'undefined') {
    alert('Yes');
}
于 2013-06-01T08:27:39.720 回答