writeFile 及 writeFileSync 在电脑版中失灵
发布于 4 年前 作者 guiying67 10750 次浏览 来自 问答

就用 API 文档中的示例代码,在开发者工具及手机上正常,在微信电脑版中却无效,虽然没有报错,但什么文件都没有生成。

原因可能是刚刚升级到了3.3.0.93,在此之前也是正常的。

const fs = wx.getFileSystemManager()
fs.writeFile({
  filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,
  data: 'some text or arrayBuffer',
  encoding: 'utf8',
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})

// 同步接口
try {
  const res = fs.writeFileSync(
    `${wx.env.USER_DATA_PATH}/hellosync.txt`,
    'some text or arrayBuffer',
    'utf8'
  )
  console.log(res)
} catch(e) {
  console.error(e)
}
  

运行之后进 dos,在 C:\> 下执行 dir hello*.txt /s/a,只能找到在开发者工具中运行生成的两个文件,通过微信电脑版运行则没有生成。

1 回复

请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

回到顶部