<template>
  <div>
    {{ time }}秒后可重新呼叫
  </div>
</template>
<script>
  export default {
    name: 'TimeLeft',
    props:['timeleft'],
    data() {
      return {
        timer: null,
        time:60
      };
    },
    mounted() {
      clearInterval(this.timer);
      if (this.timeleft > 0) {
        this.time = this.timeleft;
        this.down();
      }
    },
    methods: {
      down() {
        this.timer = setInterval(() => {
          this.time--;
          if (this.time === 0) {
            this.$emit('setItem');
            clearInterval(this.timer);
          }
        }, 1000);
      },
    },
  };
</script>

<style lang="scss" scoped>
</style>
