vue-plugin-timer

0.3.3 • Public • Published

vue plugin timer

An easy way to use setTimeout and setInterval.

Install

npm i vue-plugin-timer

Usage

import Vue from 'vue';
import Timer from 'vue-plugin-timer';
 
Vue.use(Timer);

Then in Vue lifecycle hooks, use this.$setTimeout this.$setInterval this.$clearTimeout this.$clearInterval replace the methods of window.

All timers will be cleared when component destroyed.

<script>
export default {
  props: ['message'],
  mounted() {
    // use window.setTimeout
    this.timer = window.setTimeout(() => console.log(this.message), 60 * 1000);
    // use vue-plugin-timer
    this.$setTimeout(() => console.log(this.message), 60 * 1000);
  },
  destroyed() {
    window.clearTimeout(this.timer);
  }
}
</script> 

License

Copyright © 2018-present wmzy. This source code is licensed under the MIT license found in the LICENSE.txt file.

Package Sidebar

Install

npm i vue-plugin-timer

Weekly Downloads

4

Version

0.3.3

License

none

Unpacked Size

63.4 kB

Total Files

9

Last publish

Collaborators

  • wmzy