diff --git a/src/v2/guide/filters.md b/src/v2/guide/filters.md index c99baacdb1..984ea17c12 100644 --- a/src/v2/guide/filters.md +++ b/src/v2/guide/filters.md @@ -14,21 +14,30 @@ Vue.js allows you to define filters that can be used to apply common text format
``` -The filter function always receives the expression's value (the result of the former chain) as its first argument. In this example, the `capitalize` filter function will receive the value of `message` as its argument. +You can define local filters in a component's options: ``` js -new Vue({ - // ... - filters: { - capitalize: function (value) { - if (!value) return '' - value = value.toString() - return value.charAt(0).toUpperCase() + value.slice(1) - } +filters: { + capitalize: function (value) { + if (!value) return '' + value = value.toString() + return value.charAt(0).toUpperCase() + value.slice(1) } +} +``` + +or define a filter globally: + +``` js +Vue.filter('capitalize', function (value) { + if (!value) return '' + value = value.toString() + return value.charAt(0).toUpperCase() + value.slice(1) }) ``` +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: ``` html