Skip to content

Commit 3b3b9b5

Browse files
flybayerchrisvfritz
authored andcommitted
Clarify how to define filters (#1225)
* clarify how to define filters * Tweaks to filter registration examples
1 parent 91a2705 commit 3b3b9b5

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/v2/guide/filters.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,30 @@ Vue.js allows you to define filters that can be used to apply common text format
1414
<div v-bind:id="rawId | formatId"></div>
1515
```
1616

17-
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.
17+
You can define local filters in a component's options:
1818

1919
``` js
20-
new Vue({
21-
// ...
22-
filters: {
23-
capitalize: function (value) {
24-
if (!value) return ''
25-
value = value.toString()
26-
return value.charAt(0).toUpperCase() + value.slice(1)
27-
}
20+
filters: {
21+
capitalize: function (value) {
22+
if (!value) return ''
23+
value = value.toString()
24+
return value.charAt(0).toUpperCase() + value.slice(1)
2825
}
26+
}
27+
```
28+
29+
or define a filter globally:
30+
31+
``` js
32+
Vue.filter('capitalize', function (value) {
33+
if (!value) return ''
34+
value = value.toString()
35+
return value.charAt(0).toUpperCase() + value.slice(1)
2936
})
3037
```
3138

39+
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.
40+
3241
Filters can be chained:
3342

3443
``` html

0 commit comments

Comments
 (0)