一、相关链接
① 使用uni.getAccountInfoSync() : https://uniapp.dcloud.net.cn/api/other/getAccountInfoSync.html#getaccountinfosync
② 使用uni.getSystemInfo 异步获取系统信息 : https://uniapp.dcloud.net.cn/api/system/info.html#%E7%B3%BB%E7%BB%9F%E4%BF%A1%E6%81%AF%E7%9A%84%E6%A6%82%E5%BF%B5
二、方法描述
① 使用 uni.getAccountInfoSync() (推荐)
该方法仅支持在正式版小程序中获取,开发和体验版中是无法获取的
const accountInfo = uni.getAccountInfoSync(); console.log(accountInfo.miniProgram.appId); // 小程序 appId console.log(accountInfo.miniProgram.envVersion); // 小程序 当前环境版本:develop开发版、trial体验版、release正式版、gray灰度版(仅支付宝小程序支持) console.log(accountInfo.miniProgram.version); // 线上小程序版本号(仅在正式版小程序上支持)
② 使用 uni.getSystemInfo (uni-app提供了异步(uni.getSystemInfo
)和同步(uni.getSystemInfoSync
)的2个API获取系统信息。)
该方法 主要获取系统信息 但是如果需要获取版本的话 每次都需要修改manifest.json 的versionName这个字段(不推荐)
uni.getSystemInfo({ success:res => { this.versionNum = res.appVersion; } })
注:该文档为个人理解所写,有误可建议修改