uniapp实现app版本更新

app 版本更新弹框提示


"show" :content="content" title="升级提示" @confirm="confirm">

js 实现过程

<script>
	//此文件在下边
	import { isEmpty } from "../../common/util";
	export default {
		data() {
			return {
				show: false,
				content: '',
				downloadUrl: ''
			}
		},
		onLoad() {
			this.checkAppVersion()
		},
		methods: {
			async checkAppVersion() {
				//检测更新
				//#ifdef APP-PLUS
				this.show = false
				this.downloadUrl = ''
				let params = {
					appId: plus.runtime.appid,
					version: plus.runtime.version
				}
				//版本更新接口
				await this.$api.api.home.getAppUpdate(params).then(res => {
					if (!isEmpty(res.body)) {
						//有更新时将下载链接存入缓存并隐藏tabbar
						uni.hideTabBar()
						this.show = true;
						this.content = res.body.note
						this.downloadUrl = res.body.downloadUrl
					}
				})
				//#endif
			},
			confirm() {
				if (!isEmpty(this.downloadUrl)) {
					plus.runtime.openURL(this.downloadUrl)
				}
				uni.showTabBar()
				this.show = false;
			},
		}
	}
</script>

util 文件封装内容

export const isEmpty = function(val) {
	// null or undefined
	if (val == null) return true;
	if (typeof val === 'boolean') return false;
	if (typeof val === 'number') return !val;
	if (val instanceof Error) return val.message === '';
	switch (Object.prototype.toString.call(val)) {
		// String or Array
		case '[object String]':
		case '[object Array]':
		return !val.length;
		// Map or Set or File
		case '[object File]':
		case '[object Map]':
		case '[object Set]': {
			return !val.size;
		}
		// Plain Object
		case '[object Object]': {
			return !Object.keys(val).length;
		}
	}
	return false;
};

你可能感兴趣的:(app)