Skip to content
Advertisement

Vue, adding/incrementing time in ‘xhxxm’ format

I’m trying to make a simple interface where a user can increment time using a number of options available in a list. I have it working to set the vue variable as the time that they click on (i.e. if they click ‘+30m’ then the variable reflects 30

However, I’d like to display the variable in the format of XhXXm (so 2 hours and 30 minutes would be 2h30m). The trick is, if they select 15m, then 30m and then 1h, the display should read 1h45m.

How would I alter this in order to actually iterate properly and add up the selections? Should I add it all into minutes and then try to break it out for the UI?

JavaScript

Advertisement

Answer

Start with timeSpent at 0

JavaScript

set your function to add the new value to your counter

JavaScript

and to format Computed Property

JavaScript

finally to display

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement