Skip to content

Commit 508f797

Browse files
author
勾股
committed
translated custom-filter and events
1 parent 2baeb2f commit 508f797

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

source/guide/custom-filter.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ type: guide
33
order: 10
44
---
55

6-
## The Basics
6+
## 基本用法
77

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:
8+
和自定义指令类似,你可以用全局方法 `Vue.filter()`,传递一个**过滤器 ID**和一个**过滤器函数**,注册一个自定义过滤器。过滤器函数会接受一个参数值并返回将其转换后的值:
99

1010
``` js
1111
Vue.filter('reverse', function (value) {
@@ -18,7 +18,7 @@ Vue.filter('reverse', function (value) {
1818
<span v-text="message | reverse"></span>
1919
```
2020

21-
The filter function also receives any inline arguments:
21+
过滤器函数也接受任何内联的参数:
2222

2323
``` js
2424
Vue.filter('wrap', function (value, begin, end) {
@@ -31,9 +31,9 @@ Vue.filter('wrap', function (value, begin, end) {
3131
<span v-text="message | wrap before after"></span>
3232
```
3333

34-
## Two-way Filters
34+
## 双向过滤器
3535

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):
36+
现在我们已经在展示视图之前用过滤器把模型里的值进行了转换。其实我们也可以定义一个过滤器在值从视图 (input 元素) 写回模型之前进行转换:
3737

3838
``` js
3939
Vue.filter('check-email', {
@@ -50,9 +50,9 @@ Vue.filter('check-email', {
5050
})
5151
```
5252

53-
## Filter Context
53+
## 过滤器上下文
5454

55-
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.
55+
当一个过滤器被调用的时候,其 `this` 上下文会被设置为调用它的 Vue 实例。这使得我们可以根据其所属的 Vue 实例动态输出结果。
5656

5757
For example:
5858

@@ -67,8 +67,8 @@ Vue.filter('concat', function (value, key) {
6767
<span>{&#123;msg | concat userInput&#125;}</span>
6868
```
6969

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.
70+
在上面这个例子中,你用表达式即可完成相同的结果。但是面对更复杂的处理时,如果需要不止一个语句,你就得把它们放到一个可推导的属性中或一个自定义过滤器中。
7171

72-
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.
72+
内建的 `filterBy` `orderBy` 过滤器都是根据传入的数组以及所属 Vue 实例状态而运行的过滤器。
7373

74-
Alright! Now it's time to learn how the [Component System](../guide/components.html) works.
74+
Alright!是时候了解[组件系统](../guide/components.html)的工作方式了。

source/guide/events.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ type: guide
33
order: 6
44
---
55

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
77

88
``` html
99
<div id="demo">
@@ -27,9 +27,9 @@ new Vue({
2727
})
2828
```
2929

30-
## Invoke Handler with Expression
30+
## 执行表达式句柄
3131

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:
32+
`targetVM` `v-repeat` 里使用 `v-on` 时显得特别有用,因为 `v-repeat` 会创建大量子 ViewModel。这样的话,通过执行表达式的方式,把代表当前上下文 ViewModel 的 `this` 传进去,就显得非常方便。
3333

3434
``` html
3535
<ul id="list">
@@ -54,7 +54,7 @@ new Vue({
5454
})
5555
```
5656

57-
When you want to access the original DOM event in an expression handler, you can pass it in as `$event`:
57+
当你想要在表达式句柄中访问原来的 DOM event,你可以传递一个 `$event` 参数进去:
5858

5959
``` html
6060
<button v-on="click: submit('hello!', $event)">Submit</button>
@@ -72,30 +72,30 @@ When you want to access the original DOM event in an expression handler, you can
7272
/* ... */
7373
```
7474

75-
## The Special `key` Filter
75+
## 特殊的 `key` 过滤器
7676

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:
77+
当监听键盘事件时,我们常常需要判断常用的 key code。Vue.js 提供了一个特殊的只能用在 `v-on` 指令的过滤器:`key`。它接收一个表示 key code 的参数并完成判断:
7878

7979
```
8080
<!-- only call vm.submit() when the keyCode is 13 -->
8181
<input v-on="keyup:submit | key 13">
8282
```
8383

84-
It also has a few presets for commonly used keys:
84+
它也预置了一些常用的按键名:
8585

8686
```
8787
<!-- same as above -->
8888
<input v-on="keyup:submit | key enter">
8989
```
9090

91-
Check the API reference for a [full list of key filter presets](../api/filters.html#key).
91+
API 索引中有 [key 过滤器预置的完整列表](../api/filters.html#key).
9292

93-
## Why Listeners in HTML?
93+
## 为什么要在 HTML 中写监听器?
9494

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` 还有更多好处:
9696

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 无关。这会更易于测试。
99+
3. 当一个 ViewModel 被销毁时,所有的事件监听都会被自动移除。你无须担心如何自行清理它们。
100100

101-
Next up: [Handling Forms](../guide/forms.html).
101+
接下来:[处理表单](../guide/forms.html).

0 commit comments

Comments
 (0)