Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- Timer Component -->
- <template>
- <span>{{ timer }}</span>
- </template>
- <script>
- props: {
- startTime: {
- type: String,
- default: '',
- },
- },
- data () {
- return {
- now: Date.now (),
- bias: 0,
- }
- },
- created () {
- this.runTimer ();
- },
- computed: {
- timer () {
- return moment (this.now + this.bias).format ('YYYY/MM/DD HH:mm:ss');
- },
- },
- methods: {
- runTimer () {
- let $vmc = this;
- setInterval (() => $vmc.now = Date.now (), 1000);
- }
- },
- watch: {
- startTime () {
- if (this.start !== '')
- this.bias = moment (this.startTime).valueOf () - this.now;
- else this.bias = 0;
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement