DEV Community

Discussion on: How to format dates in Vue

Collapse
 
andreandyp profile image
André Michel Andy

You can also define a global filter for using in all components:

// main.js

import Vue from "vue";
import VueResource from "vue-resource";

// Other code...

Vue.filter("capitalize", text => {
    return text ? text.charAt(0).toUpperCase() + text.slice(1) : "";
});

//Other code...

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount("#app");

Tested on single file components. Perhaps is the same with CDN version.

Collapse
 
firstclown profile image
Joe Erickson

Yes. The filters are pretty handy. I'm planning writing a post about them soon. Thank you for pointing this out!