使用 fetch api 读取 .scss 文件

Reading a .scss file with fetch api

我正在尝试获取一个 .scss 文件,其中声明了变量,它位于我的 public 文件夹中并读取其中的文本。

这是我尝试过的:

fetch('someFolder/someFolder/_variables.scss')
      .then(response => console.log(response.data))

其中 returns 未定义。这是我第一次使用 fetch api,因此非常感谢您的帮助。

fetch 的响应是一个 Response 对象。由于它没有名为 data 的 属性,因此结果确实是未定义的。以下应该有效:

fetch('someFolder/someFolder/_variables.scss')
  .then(response => response.text()) // <----
  .then(response => console.log(response))

参见 response.text()