You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/v2/guide/syntax.md
+43-39Lines changed: 43 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,45 +80,6 @@ These expressions will be evaluated as JavaScript in the data scope of the owner
80
80
81
81
<pclass="tip">Template expressions are sandboxed and only have access to a whitelist of globals such as `Math` and `Date`. You should not attempt to access user defined globals in template expressions.</p>
82
82
83
-
### Filters
84
-
85
-
Vue.js allows you to define filters that can be used to apply common text formatting. Filters should be appended to the end of a **mustache interpolation**, denoted by the "pipe" symbol:
86
-
87
-
```html
88
-
{{ message | capitalize }}
89
-
```
90
-
91
-
<pclass="tip">Vue 2.x filters can only be used inside mustache bindings. To achieve the same behavior inside directive bindings, you should use [Computed properties](computed.html) instead.</p>
92
-
93
-
The filter function always receives the expression's value as the first argument.
Filters are JavaScript functions, therefore they can take arguments:
115
-
116
-
```html
117
-
{{ message | filterA('arg1', arg2) }}
118
-
```
119
-
120
-
Here, the plain string `'arg1'` will be passed into the filter as the second argument, and the value of expression `arg2` will be evaluated and passed in as the third argument.
121
-
122
83
## Directives
123
84
124
85
Directives are special attributes with the `v-` prefix. Directive attribute values are expected to be **a single JavaScript expression** (with the exception for `v-for`, which will be discussed later). A directive's job is to reactively apply side effects to the DOM when the value of its expression changes. Let's review the example we saw in the introduction:
@@ -157,6 +118,49 @@ Modifiers are special postfixes denoted by a dot, which indicate that a directiv
157
118
158
119
We will see more use of modifiers later when we take a more thorough look at `v-on` and `v-model`.
159
120
121
+
## Filters
122
+
123
+
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**. Filters should be appended to the end of the JavaScript expression, denoted by the "pipe" symbol:
124
+
125
+
```html
126
+
<!-- in mustaches -->
127
+
{{ message | capitalize }}
128
+
129
+
<!-- in v-bind -->
130
+
<divv-bind:id="rawId | formatId"></div>
131
+
```
132
+
133
+
<pclass="tip">Vue 2.x filters can only be used inside mustache interpolations and `v-bind` expressions (the latter supported since 2.1.0), because filters are primarily designed for text transformation purposes. For more complex data transforms in other directives, you should use [Computed properties](computed.html) instead.</p>
134
+
135
+
The filter function always receives the expression's value as the first argument.
Filters are JavaScript functions, therefore they can take arguments:
157
+
158
+
```html
159
+
{{ message | filterA('arg1', arg2) }}
160
+
```
161
+
162
+
Here, the plain string `'arg1'` will be passed into the filter as the second argument, and the value of expression `arg2` will be evaluated and passed in as the third argument.
163
+
160
164
## Shorthands
161
165
162
166
The `v-` prefix serves as a visual cue for identifying Vue-specific attributes in your templates. This is useful when you are using Vue.js to apply dynamic behavior to some existing markup, but can feel verbose for some frequently used directives. At the same time, the need for the `v-` prefix becomes less important when you are building an [SPA](https://en.wikipedia.org/wiki/Single-page_application) where Vue.js manages every template. Therefore, Vue.js provides special shorthands for two of the most often used directives, `v-bind` and `v-on`:
0 commit comments