vue 定时刷新按钮控制

vue 定时刷新按钮控制

在这里插入图片描述
在这里插入图片描述

直接上干货
在这里插入图片描述
中英文
公共组件

<template>
  <el-switch
    ref="switchObj"
    v-bind="$attrs"
    :width="width"
    :active-color="activeColor"
    :inactive-color="inactiveColor"
    v-on="$listeners"
  />
</template>
<script>
export default {
  name: 'BaseSwitch',
  props: {
    width: {
      type: Number,
      default: 42
    },
    activeColor: {
      type: String,
      default: '#13CE66'
    },
    inactiveColor: {
      type: String,
      default: '#F2F2F2'
    }
  },
  methods: {
    focus () {
      this.$refs.switchObj.focus();
    }
  }
};
</script>

中英文里面的

  mainPortal: {
    autoQuery: '自动刷新',
    hasAutoQuery: '正在刷新,请稍后',
    autoQueryTips: '{second}秒后自动刷新'

  },
   mainPortal: {
    autoQuery: 'Auto Refreshing',
    hasAutoQuery: 'Refreshing... Please wait.',
    autoQueryTips: 'Auto refreshing after {second}s'
  },

需要在那个页面那种引入就直接复制过去

<template>
  <div style="padding: 0px 20px;">
    <div class="work-order-list-header">
      <div class="header-right">
        <base-switch
          v-model="autoQuery"
          :inactive-text="autoQuery ?
            (autoQuerySecond > 0 ? $t('mainPortal.autoQueryTips',{second:autoQuerySecond}):$t('mainPortal.hasAutoQuery'))
            :$t('mainPortal.autoQuery')"
        >
        </base-switch>
      </div>
    </div>
  </div>
</template>
<script>
import BaseSwitch from '@/components/base/switch/switch';
const refreshSecond = 60;//设置刷新周期时间
export default {
  components: {
    BaseSwitch
  },
  data () {
    return {
      autoQuery: false,
      autoQuerySecond: refreshSecond,
      intervalId: null // 定时器
    };
  },
  watch: {
    autoQuery (val) {
      if (val) {
        this.setInterval();
      } else {
        this.clearInterval();
      }
    }
  },
  mounted () {
  },
  beforeDestroy () {
    this.clearInterval();
  },
  created () {
  },
  methods: {
    // 定时器
    setInterval () {
      if (this.intervalId !== null) {
        return;
      }
      // 1分钟刷一次
      this.intervalId = setInterval(() => {
        this.autoQuerySecond--;
        if (this.autoQuerySecond === 0) {
          // 刷新数据 此处调用要刷新的方法
          this.todoListSearch();
        }
      }, 1000);
    },
    // 停止定时器
    clearInterval () {
      clearInterval(this.intervalId); // 清除计时器
      this.intervalId = null; // 设置为null
      this.autoQuerySecond = refreshSecond;
    }
  }
};
</script>
<style>

</style>;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值