vue项目实现轮询定时器-关闭定时器(整理)

简介: vue项目实现轮询定时器-关闭定时器(整理)
在vue项目中我们直接在 created(){} 生命周期中写就可以了
  一、方法1
  created() {
    this.currentTime();
    setInterval(() => {
      setTimeout(() => {
        ///调取接口
        this.getStayPlace(); // 测试
      }, 0);
    }, 2 * 60 * 60000); // 两个小时
  },
方法二、
data () {
      return {
      // 定时器名称
          timer: null
    }
}
methods: {
  //判断某个是隐藏状态就关闭定时器
  getHangTotal(){ 
        if(this.dialog.tag == false){
          this.timerId = ''
          window.clearInterval(this.timer)
        }
      },
      //判断某个某个显示就执行定时器事件-下面添加判断是否空走定时器
  add () {
        this.timer = setInterval(() => {
          if(this.dialog.form.name != '' ){
            this.submitFormSb(2)
          }
        }, 5000); // 秒
      },
},
mounted: function () {
      setInterval(
        this.getHangTotal, 2000
      )
    }

感谢您的支持

相关文章
|
1天前
|
JavaScript
vue 监听 sessionStorage 中值的变化
vue 监听 sessionStorage 中值的变化
9 1
|
1天前
|
JavaScript 索引
Component name “index“ should always be multi-word vue/multi-word-component-names
Component name “index“ should always be multi-word vue/multi-word-component-names
|
1天前
|
JavaScript
文本,wangEditor5的基本使用,开发文档地址,wangEditor5用于Vue3项目,想要使用好wangEditor项目,得看开发文档
文本,wangEditor5的基本使用,开发文档地址,wangEditor5用于Vue3项目,想要使用好wangEditor项目,得看开发文档
|
1天前
|
JavaScript
vue 创建项目、运行项目、访问项目(vue2版)
vue 创建项目、运行项目、访问项目(vue2版)
6 0
|
1天前
|
JavaScript
|
1天前
|
JavaScript
Vue中data常见的写法:
Vue中data常见的写法:
|
1天前
|
Web App开发 JavaScript
vue报错【解决方案】 [Violation] Added non-passive event listener to a scroll-blocking <some> event.
vue报错【解决方案】 [Violation] Added non-passive event listener to a scroll-blocking <some> event.
5 0
|
2月前
|
JavaScript API
【vue实战项目】通用管理系统:api封装、404页
【vue实战项目】通用管理系统:api封装、404页
49 3
|
2月前
|
人工智能 JavaScript 前端开发
毕设项目-基于Springboot和Vue实现蛋糕商城系统(三)
毕设项目-基于Springboot和Vue实现蛋糕商城系统
|
2月前
|
JavaScript Java 关系型数据库
毕设项目-基于Springboot和Vue实现蛋糕商城系统(一)
毕设项目-基于Springboot和Vue实现蛋糕商城系统
112 0