前端实现定时任务

<template>
    <section>
      <h1>hello world~</h1>
    </section>
  </template>
  <script>
    export default {
      data() {
        return {
          timer: '',
          value: 0
        };
      },
      methods: {
        get() {
         
          console.log('你好');
        }
      },
      mounted() {
          // 每隔5s发送一次
        this.timer = setInterval(this.get, 5000);
      },
      beforeDestroy() {
        clearInterval(this.timer);
      }
    };
  </script>

  

原文地址:https://www.cnblogs.com/zhangshijiezsj/p/14180626.html