vue-plugin-timer
v0.3.3
Published
> An easy way to use setTimeout and setInterval.
Downloads
30
Maintainers
Readme
vue plugin timer
An easy way to use setTimeout and setInterval.
Install
npm i vue-plugin-timerUsage
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.
