微信小程序获取小程序版本号与服务器不符,微信小程序版本号比较
首先獲取到當(dāng)前版本號(hào) :
wx.getSystemInfo({
success (res) {
console.log(res.model) //獲取設(shè)備名:iPhone,Meizu......
console.log(res.version) //獲取版本號(hào)
}
})
版本號(hào)比較:
function compareVersion(v1, v2) {
v1 = v1.split('.')
v2 = v2.split('.')
var len = Math.max(v1.length, v2.length)
while (v1.length < len) {
v1.push('0')
}
while (v2.length < len) {
v2.push('0')
}
for (var i = 0; i < len; i++) {
var num1 = parseInt(v1[i])
var num2 = parseInt(v2[i])
if (num1 > num2) {
return 1
} else if (num1 < num2) {
return -1
}
}
return 0
}
compareVersion('7.0.5', '6.0.6') // => 1 // 1表示 1比2要新
compareVersion('7.0.5', '1.11.0') // => 0 // 0表示1和2是同一個(gè)版本
compareVersion('7.0.5', '6.0.6') // => -1 // -1表示1比 2要老
總結(jié)
以上是生活随笔為你收集整理的微信小程序获取小程序版本号与服务器不符,微信小程序版本号比较的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大数据和人工智能,入门书籍推荐
- 下一篇: linux系统pcre是什么作用,Lin