fengyuanchen / vue-countdown

Countdown component for Vue.js.
https://fengyuanchen.github.io/vue-countdown/
MIT License
690 stars 89 forks source link

Make :showHours dynamic #62

Closed CristianGrigorita closed 3 years ago

CristianGrigorita commented 3 years ago

Hello,

I would like to set :showHours based on a variable, something like :showHours="this.hasHours". this.hasHours is true or false, depending on the time selected by the user. In my case the countdown can be selected to take only minutes and in this case I don't want to show the hours.

How should I accomplish this, as the countdown does not change dynamically, as it does if I change the time set with :deadline="this.time_end" ?

fengyuanchen commented 3 years ago

You can override the hours in the transform prop function, for examples:

export default {
  methods: {
    transformSlotProps(props) {
      const formattedProps = {};

      Object.entries(props).forEach(([key, value]) => {
        formattedProps[key] = key === 'hours' ? 0 : value;
      });

      return formattedProps;
    },
  },
};