找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 4055|回复: 1

vue 定时器(一次性,周期)

[复制链接]
发表于 2022-11-20 14:37:11 | 显示全部楼层 |阅读模式
一次性
const that = this
setTimeout(function () {
that.$emit('refreshDataList')
}, 1000)
周期
return {
  timing: null
}
this.timer = setInterval(() => { // 启用
  that.news()
}, 10000)
beforeDestroy () { // 退出时销毁
  clearInterval(this.timer)
}

回复

使用道具 举报

 楼主| 发表于 2022-11-20 14:37:26 | 显示全部楼层
let time = 60
        let timer = setInterval(() => {
          if (time === 0) {
            clearInterval(timer)
            this.disabled = false
            this.btnTitle = '获取验证码'
          } else {
            this.btnTitle = time + '秒后重试'
            this.disabled = true
            time--
          }
        }, 1000)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|企业数字化人才转型教练中心 ( 湘ICP备15006648号-1 )

GMT+8, 2024-10-23 07:39 , Processed in 0.062242 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表