wx.saveFile把文件保存在本地,关闭微信小程序后再次启动也依然可以获取到该文件
本地文件存储的大小限制为10MB
wx.saveFile的参数说明

index.wxml<view><button bindtap='saveFile'>保存文件</button><button bindtap='openFile'>打开文件</button><image src="{{filePath}}" mode='aspectFit'></image></view>
index.jsPage({data: {filePath:""},onLoad: function(){let filePath = wx.getStorageSync("filepath") || ""this.setData({filePath})},saveFile: function(){wx.chooseImage({success(res) {const tempFilePaths = res.tempFilePathswx.saveFile({tempFilePath: tempFilePaths[0],success(res) {const savedFilePath = res.savedFilePathwx.setStorageSync("filepath", savedFilePath)}})}})}})
使用wx.chooseImage获取到一张图片
把文件的临时路径tempFilePaths传入wx.saveFile
调用wx.saveFile保存文件
得到文件的保存路径savedFilePath
再把savedFilePath使用本地存储wx.setStorageSync保存在本地
这样,微信小程序重新启动时,在onLoad生命周期函数内获取到保存的文件路径,通过数据绑定显示在页面上
