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: source/guide/custom-filter.md
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,9 @@ type: guide
3
3
order: 10
4
4
---
5
5
6
-
## The Basics
6
+
## 基本用法
7
7
8
-
Similar to custom directives, you can register a custom filter with the global `Vue.filter()` method, passing in a **filterID** and a **filter function**. The filter function takes a value as the argument and returns the transformed value:
@@ -18,7 +18,7 @@ Vue.filter('reverse', function (value) {
18
18
<spanv-text="message | reverse"></span>
19
19
```
20
20
21
-
The filter function also receives any inline arguments:
21
+
过滤器函数也接受任何内联的参数:
22
22
23
23
```js
24
24
Vue.filter('wrap', function (value, begin, end) {
@@ -31,9 +31,9 @@ Vue.filter('wrap', function (value, begin, end) {
31
31
<spanv-text="message | wrap before after"></span>
32
32
```
33
33
34
-
## Two-way Filters
34
+
## 双向过滤器
35
35
36
-
Up till now we have used filters to transform values coming from the model and before displaying them in the view. But it is also possible to define a filter that transforms the value before it is written back to the model from the view (input elements):
When a filter is invoked, its `this`context is set to the Vue instance that is invoking it. This allows it to output dynamic results based on the state of the owner Vue instance.
@@ -67,8 +67,8 @@ Vue.filter('concat', function (value, key) {
67
67
<span>{{msg | concat userInput}}</span>
68
68
```
69
69
70
-
For this simple example above, you can achieve the same result with just an expression, but for more complicated procedures that need more than one statements, you need to put them either in a computed property or a custom filter.
The built-in `filterBy`and`orderBy`filters are both filters that perform non-trivial work on the Array being passed in and relies on the current state of the owner Vue instance.
Copy file name to clipboardExpand all lines: source/guide/events.md
+14-14Lines changed: 14 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ type: guide
3
3
order: 6
4
4
---
5
5
6
-
You can use the `v-on`directive to bind event listeners to DOM events. It can be bound to either an event handler function (without the invocation parentheses) or an inline expression. If a handler function is provided, it will get the original DOM event as the argument. The event also comes with an extra property: `targetVM`, pointing to the particular ViewModel the event was triggered on:
6
+
你可以使用 `v-on`指令来绑定并监听 DOM 事件。绑定的内容可以是一个事件句柄函数 (后面无需跟括号) 或一个内联表达式。如果提供的是一个句柄函数,则原来的 DOM event 对象会被作为第一个参数传入,同时这个 event 对象会附带 `targetVM` 属性,指向触发该事件的相应的 ViewModel:
7
7
8
8
```html
9
9
<divid="demo">
@@ -27,9 +27,9 @@ new Vue({
27
27
})
28
28
```
29
29
30
-
## Invoke Handler with Expression
30
+
## 执行表达式句柄
31
31
32
-
`targetVM`could be useful when `v-on`is used with `v-repeat`, since the latter creates a lot of child ViewModels. However, it is often more convenient to use an invocation expression passing in `this`, which equals the current context ViewModel:
@@ -72,30 +72,30 @@ When you want to access the original DOM event in an expression handler, you can
72
72
/* ... */
73
73
```
74
74
75
-
## The Special `key`Filter
75
+
## 特殊的 `key`过滤器
76
76
77
-
When listening for keyboard events, we often need to check for common key codes. Vue.js provides a special `key` filter that can only be used with `v-on`directives. It takes a single argument that denotes the key code to check for:
<!-- only call vm.submit() when the keyCode is 13 -->
81
81
<input v-on="keyup:submit | key 13">
82
82
```
83
83
84
-
It also has a few presets for commonly used keys:
84
+
它也预置了一些常用的按键名:
85
85
86
86
```
87
87
<!-- same as above -->
88
88
<input v-on="keyup:submit | key enter">
89
89
```
90
90
91
-
Check the API reference for a [full list of key filter presets](../api/filters.html#key).
91
+
API 索引中有 [key 过滤器预置的完整列表](../api/filters.html#key).
92
92
93
-
## Why Listeners in HTML?
93
+
## 为什么要在 HTML 中写监听器?
94
94
95
-
You might be concerned about this whole event listening approach violates the good old rules about "separation of concern". Rest assured - since all Vue.js handler functions and expressions are strictly bound to the ViewModel that's handling the current View, it won't cause any maintainance difficulty. In fact, there are several benefits in using `v-on`:
95
+
你可能会注意到整个事件监听的方式违背了“separation of concern”的传统理念。不必担心,因为所有的 Vue.js 句柄函数和表达式都严格绑定在当前视图的 ViewModel 上,它不会导致任何维护困难。实际上,使用 `v-on` 还有更多好处:
96
96
97
-
1.It makes it easier to locate the handler function implementations within your JS code by simply skimming the HTML template.
98
-
2.Since you don't have to manually attach event listeners in JS, your ViewModel code can be pure logic and DOM-free. This makes it easier to test.
99
-
3.When a ViewModel is destroyed, all event listeners are automatically removed. You don't need to worry about cleaning it up yourself.
97
+
1.它便于在 HTML 模板中轻松定位 JS 代码里的句柄函数实现。
98
+
2.因为你无须在 JS 里手动绑定事件,你的 ViewModel 代码可以是非常纯粹的逻辑而和 DOM 无关。这会更易于测试。
0 commit comments