Vue.js Filters

Applying Filters For Text Formatting

Harsha
TheLeanProgrammer
2 min readFeb 19, 2021

--

Vue.js allows you to define filters that can be used to apply common text formatting.

Filters are usable in two places:

You can define a filter locally in a component’s options or globally before creating the Vue instance:

When the global filter has the same name as the local filter, the local filter will be preferred.

Filters can be chained:

Filters are JavaScript functions, therefore they can take arguments:

Filters are removed from Vue 3.0 and no longer supported.

It has been recommended to replace them with method calls or computed properties.

If you are using filters that were globally registered and then used throughout your app, it’s likely not convenient to replace them with computed properties or methods in each individual component.
Instead, you can make your global filters available to all components through globalProperties.

Don’t forget to follow The Lean Programmer Publication for more such articles, and subscribe to our newsletter tinyletter.com/TheLeanProgrammer

--

--