onLoad(option) {
			if (option.ids == 1) {
				this.PageCur = 'news'
			}
			this.location()
			if (this.userInfo.id) {
				this.getNewNums()
				this.getMess()
			}
		},

	async getNewNums() {
				const dates = {
					id: this.userInfo.id
				}
				const requestPayload = {
					wxDate: this.getParams(dates)
				}
				const retult = await this.$request('/benefit/wx/reviewMessage/getUnCount', this.$FlieHeader,
					requestPayload, 'post')
				// 如果请求失败,则终止函数执行
				if (retult.code !== 200) return
				this.updateNums(retult.data.data)
			},
			async getMess() {
				let timer = setInterval(() => {
					this.fun(timer)
				}, 10000)
			},
			fun(timer) {
				setTimeout(() => {
					// 这里ajax 请求的代码片段和判断是否停止定时器
					this.getNewNums()
					// 如需要停止定时器,只需加入以下:
					// clearInterval(timer)
				}, 0)
			},

为啥要包装一个延时器,由于setInterval不会清除定时器队列,每重复执行1次都会导致定时器叠加,最终卡死网页。 但是setTimeout是自带清除定时器的

GitHub 加速计划 / vu / vue
207.52 K
33.66 K
下载
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:1 个月前 )
73486cb5 * chore: fix link broken Signed-off-by: snoppy <michaleli@foxmail.com> * Update packages/template-compiler/README.md [skip ci] --------- Signed-off-by: snoppy <michaleli@foxmail.com> Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 3 个月前
e428d891 Updated Browser Compatibility reference. The previous currently returns HTTP 404. 3 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐