uniapp 微信小程序获取微信版本号并对比

uniapp yekong 1279℃

微信小程序开发过程中,因为微信版本过低,某些功能不能使用,需要对微信版本进行判断,当微信版本低于某个版本的时候,需要进行提示,告诉用户让用户升级微信app。

判断代码

getVersion() {
	var that = this;
	// 判断版本
	that.version = wx.getSystemInfoSync().version
	if (that.compareVersion(that.version, '7.0.15') <= 0) {
		that.lowVersion = true
		wx.showModal({
			title: '提示',
			content: '当前版本(' + that.version + ')过低,请更新到微信最新版本'
		})
		return
	}
},
compareVersion(v1, v2) {
	v1 = v1.split('.')
	v2 = v2.split('.')
	const len = Math.max(v1.length, v2.length)

	while (v1.length < len) {
		v1.push('0')
	}
	while (v2.length < len) {
		v2.push('0')
	}

	for (let i = 0; i < len; i++) {
		const num1 = parseInt(v1[i])
		const num2 = parseInt(v2[i])

		if (num1 > num2) {
			return 1
		} else if (num1 < num2) {
			return -1
		}
	}
	return 0
},
喜欢 (1)