Svelte:如何使用本机 Web API

use*_*025 1 svelte

在 Svelte 应用程序中,我们如何访问本机 Web API(例如文件系统访问 API)以使用window.showOpenFilePicker()方法?

tib*_*256 9

要获得对新 WICG 文件系统访问 API 的 Typescript 支持,您需要进行以下两项更改:

  1. 将 npm 包安装@types/wicg-file-system-access到您的开发依赖项中(即 npm npm install --save-dev @types/wicg-file-system-access)。
  2. 将类型添加到 tsconfig.json 文件
{
  ...
  "compilerOptions": {
    "types": ["@types/wicg-file-system-access"]
  }
  ...
}
Run Code Online (Sandbox Code Playgroud)