Guide
Essentials
- Installation
- Introduction
- The Vue Instance
- Template Syntax
- Computed Properties and Watchers
- Class and Style Bindings
- Conditional Rendering
- List Rendering
- Event Handling
- Form Input Bindings
- Components Basics
Components In-Depth
- Component Registration
- Props
- Custom Events
- Slots
- Dynamic & Async Components
- Handling Edge Cases
Transitions & Animation
- Enter/Leave & List Transitions
- State Transitions
Reusability & Composition
- Mixins
- Custom Directives
- Render Functions & JSX
- Plugins
- Filters
Tooling
- Single File Components
- Testing
- TypeScript Support
- Production Deployment
Scaling Up
- Routing
- State Management
- Server-Side Rendering
- Security
Internals
- Reactivity in Depth
Migrating
- Migration from Vue 1.x
- Migration from Vue Router 0.7.x
- Migration from Vuex 0.6.x to 1.0
- Migration to Vue 2.7
Meta
- Comparison with Other Frameworks
- Join the Vue.js Community!
- Meet the Team
Filters
Vue.js allows you to define filters that can be used to apply common text formatting. Filters are usable in two places: mustache interpolations and v-bind
expressions (the latter supported in 2.1.0+). Filters should be appended to the end of the JavaScript expression, denoted by the “pipe” symbol:
|
You can define local filters in a component’s options:
|
or define a filter globally before creating the Vue instance:
|
When the global filter has the same name as the local filter, the local filter will be preferred.
Below is an example of our capitalize
filter being used:
{{ message | capitalize }}
The filter’s function always receives the expression’s value (the result of the former chain) as its first argument. In the above example, the capitalize
filter function will receive the value of message
as its argument.
Filters can be chained:
|
In this case, filterA
, defined with a single argument, will receive the value of message
, and then the filterB
function will be called with the result of filterA
passed into filterB
‘s single argument.
Filters are JavaScript functions, therefore they can take arguments:
|
Here filterA
is defined as a function taking three arguments. The value of message
will be passed into the first argument. The plain string 'arg1'
will be passed into the filterA
as its second argument, and the value of expression arg2
will be evaluated and passed in as the third argument.