uniapp 版本更新弹窗 弹窗每天只弹一次

uniapp 版本更新弹窗 弹窗每天只弹一次


提示!!! 主要展示弹窗每天只弹一次的逻辑,不展示版本更新弹窗代码

在关闭版本更新弹窗处将当前年,月,日,保存本地

close(){
    
    
				this.show=false
				var time = {
    
    
					year:new Date().getFullYear(),
					month:new Date().getMonth()+1,
					date:new Date().getDate()
				}
				uni.setStorage({
    
    
					key:'version',
					data:time
				})
				this.$emit('close')
	},

在首页中比较版本号时,拿出本地缓存中的日期,与当前日期进行比较

if (this.version > version) {
    
    
						uni.getStorage({
    
    
							key: 'version',
							success: (res) => {
    
    
								var time = {
    
    
									year: new Date().getFullYear(),
									month: new Date().getMonth() + 1,
									date: new Date().getDate()
								}
								if (!res.data){
    
    
									_self.$refs.version.show = true
									return false
								}
								if (time.year > res.data.year) {
    
    
									_self.$nextTick(function() {
    
     // 年
										_self.$refs.version.show = true
									})
								} else if (time.year == res.data.year) {
    
    
									if (time.month > res.data.month) {
    
     // 月
										_self.$nextTick(function() {
    
    
											_self.$refs.version.show = true
										})
									} else if (time.month == res.data.month) {
    
    

										if (time.date > res.data.date) {
    
     // 天
											_self.$nextTick(function() {
    
    
												_self.$refs.version.show = true
											})
										}
									}
								}

							},
							fail: () => {
    
    
								var time = {
    
    
									year:new Date().getFullYear(),
									month:new Date().getMonth()+1,
									date:new Date().getDate()
								}
								uni.setStorage({
    
    
									key:'version',
									data:time
								})
							}
						})

					} 

猜你喜欢

转载自blog.csdn.net/sxmzhw/article/details/121809321