Svelte:如何使用原生 Web API

Svelte: how to use native web APIs

在 Svelte 应用程序中,我们如何访问本机 Web API,例如 File System Access API, to, for example, use the window.showOpenFilePicker() 方法?

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

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