I have an api served with django (django-rest-framework) which return a movie object and its related information into a Vue app. One of the information is the movie duration.
object:
{
"movie_id": 13,
"duration": "17:52:14",
...
...
},
component template:
<div id="movieDetailSynopsis">
...
...
<p>Duration: {{movie.duration}}</p>
</div>
The duration is in this format
HH:MM:SS
eg: 02:22:08
But what I want it to look like is in this way
2h 22m
Is there anyway to achieve this in django or vuejs or javascript?
update:
Tried using filter globaly
main.js:
new Vue({
router,
components: {App},
template: '<App/>',
store,
filters: {
durationFormat(value) {
const duration = moment.duration(value);
return duration.hours() + 'h ' + duration.minutes() + 's';
}
}
}).$mount('#app');
inside the component template:
<div id="movieDetailSynopsis">
...
...
<p>Duration: {{movie.duration | durationFormat}}</p>
</div>
But I get an error:
[Vue warn]: Failed to resolve filter: durationFormat (found in anonymous component - use the "name" option for better debugging messages.)