const fileManager = wx.getFileSystemManager();
try {
fileManager.accessSync('/env.txt');
that.globalData.ENV = ENVS.DEV;
} catch (e) {
console.log(e)
that.globalData.ENV = ENVS.PROD;
}
报错
Error: accessSync:fail no such file or directory, access "/env.txt"
at accessSync (VM663 WAService.js:1)
at Object.e.<computed> [as accessSync] (VM663 WAService.js:1)
at pe.onLaunch (app.js? [sm]:32)
at pe.<anonymous> (VM663 WAService.js:1)
at VM663 WAService.js:1
at new pe (VM663 WAService.js:1)
at Function.<anonymous> (VM663 WAService.js:1)
at VM663 WAService.js:1
at app.js? [sm]:12
at require (VM663 WAService.js:1)
无语了,怎么读都读不到。 网上也找不到正确的使用示例。 还有 一些文章就是在瞎写,居然还有人点赞,服气。
最后终于找到某些大腿评论提供的方法了。
let version = wx.getAccountInfoSync().miniProgram.envVersion
if( version == 'develop') echo '开发版';
if( version == 'trial') echo '体验版';
if( version == 'release') echo '正式版';
https://developers.weixin.qq.com/miniprogram/dev/api/open-api/account-info/wx.getAccountInfoSync.html
fileManager.accessSync(wx.env.USER_DATA_PATH +'/env.txt');
这样也不行,无语了
小程序没有根目录这个概念,你就用相对目录去试试 ../ 直到目录正确为止。