From aceaea07c26698852628d6b8c1e09ea7c3a39202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E4=B8=80=E9=B8=A3?= <315129552@qq.com> Date: Sat, 13 Aug 2016 21:05:53 +0800 Subject: [PATCH 01/78] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=89=8D=E5=8D=8A?= =?UTF-8?q?=E9=83=A8=E5=88=86=E7=BF=BB=E8=AF=91=E7=9A=84=E4=B8=AD=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/guide/class-and-style.md | 64 ++++++++++---------- src/guide/computed.md | 64 ++++++++++---------- src/guide/conditional.md | 44 +++++++------- src/guide/index.md | 30 +++++----- src/guide/installation.md | 55 +++++++++--------- src/guide/instance.md | 53 +++++++++-------- src/guide/overview.md | 51 ++++++++-------- src/guide/syntax.md | 109 +++++++++++++++++------------------ 8 files changed, 237 insertions(+), 233 deletions(-) diff --git a/src/guide/class-and-style.md b/src/guide/class-and-style.md index b95af975a8..585874baf4 100644 --- a/src/guide/class-and-style.md +++ b/src/guide/class-and-style.md @@ -1,42 +1,45 @@ --- -title: Class and Style Bindings +title: Class 与 Style 绑定 type: guide order: 6 --- -A common need for data binding is manipulating an element's class list and its inline styles. Since they are both attributes, we can use `v-bind` to handle them: we just need to calculate a final string with our expressions. However, meddling with string concatenation is annoying and error-prone. For this reason, Vue provides special enhancements when `v-bind` is used with `class` and `style`. In addition to strings, the expressions can also evaluate to objects or arrays. +数据绑定一个常见需求是操作元素的 class 列表和它的内联样式。因为它们都是 attribute,我们可以用 `v-bind` 处理它们:只需要计算出表达式最终的字符串。不过,字符串拼接麻烦又易错。因此,在 `v-bind` 用于 `class` 和 `style` 时,Vue.js 专门增强了它。表达式的结果类型除了字符串之外,还可以是对象或数组。 -## Binding HTML Classes +## 绑定 HTML Class -### Object Syntax +
尽管可以用 Mustache 标签绑定 class,比如 `{% raw %}class="{{ className }}"{% endraw %}`,但是我们不推荐这种写法和 `v-bind:class` 混用。两者只能选其一!
-We can pass an object to `v-bind:class` to dynamically toggle classes: +### 对象语法 -``` html +我们可以传给 `v-bind:class` 一个对象,以动态地切换 class。 + +```html ``` -``` js + +```js data: { isActive: true, hasEror: false } ``` -The `v-bind:class` directive can also co-exist with the plain `class` attribute: +`v-bind:class` 指令可以与普通的 `class` 特性共存: ``` html ``` -This will render: +渲染为: ``` html ``` -When `isActive` or `hasError` changes, the class list will be updated accordingly. For example, if `hasError` becomes `true`, the class list will become `"static active text-danger"`. +当 `isActive` 和 `hasError` 变化时,class 列表将相应地更新。例如,如果 `hasError` 变为 `true`,class 列表将变为 `"static active text-danger"`。 -You can also directly bind to an object: +你也可以直接绑定数据里的一个对象: ``` html @@ -50,12 +53,13 @@ data: { } ``` -This will render the same result. We can also bind to a [computed property](computed.html) that returns an object. This is a common and powerful pattern: +我们也可以在这里绑定一个返回对象的[计算属性](computed.html)。这是一个常用且强大的模式。 -``` html +```html ``` -``` js + +```js data: { isActive: true, error: null @@ -70,13 +74,14 @@ computed: { } ``` -### Array Syntax +### 数组语法 -We can pass an array to `v-bind:class` to apply a list of classes: +我们可以把一个数组传给 `v-bind:class`,以应用一个 class 列表: ``` htmlOriginal message: "{{ message }}"
Computed reversed message: "{{ reversedMessage }}"
Ask a yes/no question: @@ -166,7 +165,7 @@ For example:
Ask a yes/no question: @@ -240,6 +240,7 @@ var watchExampleVM = new Vue({ answer: 'I cannot give you an answer until you ask a question!' }, watch: { + // whenever question changes, this function will run question: function (newQuestion) { this.answer = 'Waiting for you to stop typing...' this.getAnswer() @@ -262,6 +263,8 @@ var watchExampleVM = new Vue({ vm.answer = 'Error! Could not reach the API. ' + error }) }, + // This is the number of milliseconds we wait for the + // user to stop typing. 500 ) } @@ -269,4 +272,5 @@ var watchExampleVM = new Vue({ {% endraw %} -In this case, using the `watch` option allows us to perform an asynchronous operation (accessing an API), limit how often we perform that operation, and set intermediary states until we get a final answer. None of that would be possible with a computed property. + +在这个示例中,使用watch的设置允许我们执行异步操作(访问一个接口),限制我们多久执行该操作,并在我们获取最终结果时立刻设置状态。这是计算属性无法做到的。 diff --git a/src/guide/conditional.md b/src/guide/conditional.md index de4b35b746..b1c5c23908 100644 --- a/src/guide/conditional.md +++ b/src/guide/conditional.md @@ -1,36 +1,36 @@ --- -title: Conditional Rendering +title: 条件渲染 type: guide order: 7 --- ## v-if -In string templates, for example Handlebars, we would write a conditional block like this: +在字符串模板中,如 Handlebars,我们得像这样写一个条件块: ``` html - + {{#if ok}}
Note that `v-show` doesn't support the `` syntax.
+注意 `v-show` 不支持 `` 语法。 ## v-else -You can use the `v-else` directive to indicate an "else block" for `v-if` or `v-show`: +可以用 `v-else` 指令给 `v-if` 或 `v-show` 添加一个 "else 块": ``` htmlThis could be a component too
+这可能也是一个组件
``` -Replace the `v-else` with another `v-show`: +用另一个 `v-show` 替换 `v-else`: ```htmlThis could be a component too
+这可能也是一个组件
``` -It does work as intended with `v-if`. +这样就可以达到 `v-if` 的效果。 ## v-if vs. v-show -When a `v-if` block is toggled, Vue will have to perform a partial compilation/teardown process, because the template content inside `v-if` can also contain data bindings or child components. `v-if` is "real" conditional rendering because it ensures that event listeners and child components inside the conditional block are properly destroyed and re-created during toggles. +在切换 `v-if` 块时,Vue.js 有一个局部编译/卸载过程,因为 `v-if` 之中的模板也可能包括数据绑定或子组件。`v-if` 是真实的条件渲染,因为它会确保条件块在切换当中合适地销毁与重建条件块内的事件监听器和子组件。 -`v-if` is also **lazy**: if the condition is false on initial render, it will not do anything - partial compilation won't start until the condition becomes true for the first time (and the compilation is subsequently cached). +`v-if` 也是**惰性的**:如果在初始渲染时条件为假,则什么也不做——在条件第一次变为真时才开始局部编译(编译会被缓存起来)。 -In comparison, `v-show` is much simpler - the element is always compiled and preserved, with just simple CSS-based toggling. +相比之下,`v-show` 简单得多——元素始终被编译并保留,只是简单地基于 CSS 切换。 -Generally speaking, `v-if` has higher toggle costs while `v-show` has higher initial render costs. So prefer `v-show` if you need to toggle something very often, and prefer `v-if` if the condition is unlikely to change at runtime. +一般来说,`v-if` 有更高的切换消耗而 `v-show` 有更高的初始渲染消耗。因此,如果需要频繁切换 `v-show` 较好,如果在运行时条件不大可能改变 `v-if` 较好。 diff --git a/src/guide/index.md b/src/guide/index.md index 54f6275b41..3cf3e91bf9 100644 --- a/src/guide/index.md +++ b/src/guide/index.md @@ -1,12 +1,12 @@ --- -title: Getting Started +title: 起步 type: guide order: 1 --- -Let's start with a quick tour of Vue's data binding features. If you are more interested in a high-level overview first, check out this [blog post](!!TODO: HIGH LEVEL OVERVIEW FOR RELEASED 2.0). If you are already familiar with Vue 1.0, the [migration guide](!!TODO: MIGRATION GUIDE FROM 1.0 to 2.0) may be a good place to start. +我们以 Vue 数据绑定的快速导览开始。如果你对高级概述更感兴趣,可查看这篇[博文](http://blog.evanyou.me/2015/10/25/vuejs-re-introduction/)。如果你已经对Vue 1.0非常熟悉,这篇[迁移指南](http://rc.vuejs.org/guide/!!TODO:%20MIGRATION%20GUIDE%20FROM%201.0%20to%202.0)可能是个很好的开端。 -The easiest way to try out Vue.js is using the [JSFiddle Hello World example](https://jsfiddle.net/chrisvfritz/ng41aepx/). Feel free to open it in another tab and follow along as we go through some basic examples. If you prefer downloading / installing from a package manager, check out the [Installation](/guide/installation.html) page. +尝试 Vue.js 最简单的方法是使用 [JSFiddle Hello World 例子](https://jsfiddle.net/chrisvfritz/ng41aepx/)。在浏览器新标签页中打开它,跟着我们查看一些基础示例。如果你喜欢用包管理器下载/安装,查看[安装](/guide/installation.html)教程。 ### Hello World @@ -37,7 +37,7 @@ new Vue({ {% endraw %} -### Two-way Binding +### 双向绑定 ``` htmlDynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead to [XSS attacks](https://en.wikipedia.org/wiki/Cross-site_scripting). Only use HTML interpolation on trusted content and **never** on user-provided content.
+在网站上动态渲染任意 HTML 是非常危险的,因为容易导致 [XSS 攻击](https://en.wikipedia.org/wiki/Cross-site_scripting)。记住,只对可信内容使用 HTML 插值,**永不**用于用户提交的内容。
-### Attributes +### HTML 特性 -Mustaches cannot be used inside HTML attributes, instead use a [v-bind directive](!!TODO): +Mustache 标签不可以用在 HTML 特性 (Attributes) 内,用一个[v-bind指令](http://rc.vuejs.org/guide/!!TODO)替换它 -## Binding Expressions +## 绑定表达式 -The text we put inside mustache tags are called **binding expressions** with an additional [syntax sugar for filters](#Filters). In Vue.js, a binding expression consists of a single JavaScript expression. +放在 Mustache 标签内的文本称为**绑定表达式**。在 Vue.js 中,一段绑定表达式由一个简单的 JavaScript 表达式和一个可选的额外的[过滤器语法糖](http://rc.vuejs.org/guide/syntax.html#Filters)组成。 -### JavaScript Expressions +### JavaScript 表达式 -So far we've only been binding to simple property keys in our templates. But Vue.js actually supports the full power of JavaScript expressions inside data bindings: +到目前为止,我们的模板只绑定到简单的属性键。不过实际上 Vue.js 在数据绑定内支持全功能的 JavaScript 表达式: ``` html {{ number + 1 }} @@ -58,29 +57,28 @@ So far we've only been binding to simple property keys in our templates. But Vue {{ message.split('').reverse().join('') }} ``` -These expressions will be evaluated in the data scope of the owner Vue instance. One restriction is that each binding can only contain **one single expression**, so the following will **NOT** work: +这些表达式将在所属的 Vue 实例的作用域内计算。一个限制是每个绑定只能包含**单个表达式**,因此下面的语句是**无效**的: ``` html - + {{ var a = 1 }} - + {{ if (ok) { return message } }} ``` -### Filters +### 过滤器 -Vue.js allows you to define filters that can be later on appended to the end of a **mustache** **binding expression**, denoted by the "pipe" symbol: +Vue.js 允许在表达式后添加可选的“过滤器 (Filter) ”,以“管道符”指示: ``` html {{ message | capitalize }} ``` +Vue 2 的过滤器只可以被用在mustache绑定中。为了获得在其它绑定表达式中一样的行为,你可以使用[计算属性](http://rc.vuejs.org/guide/!!TODO)替代它
-Vue 2 filters can only be used inside mustache bindings. To achieve the same behavior inside other binding expressions, you should use [Computed properties](!!TODO) instead.
- -The filter function always receives the expression's value as the first argument. +过滤器函数总是接受表达式只做为第一个参数 -``` js +``` new Vue({ ... filters: { @@ -93,89 +91,86 @@ new Vue({ }) ``` -Filters can be chained: +过滤器可以串联: ``` html {{ message | filterA | filterB }} ``` -Filters are JavaScript functions, therefore they can take arguments: +过滤器也是javascript函数,也可以接受参数: ``` html -{{ message | filterA('arg1', arg2) }} +{{ message | filterA 'arg1' arg2 }} ``` -Quoted arguments are interpreted as plain strings, while un-quoted ones will be evaluated as expressions. 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. +过滤器函数始终以表达式的值作为第一个参数。带引号的参数视为字符串,而不带引号的参数按表达式计算。这里,字符串 `'arg1'` 将传给过滤器作为第二个参数,表达式 `arg2` 的值在计算出来之后作为第三个参数。 -## Directives +## 指令 -Directives are special attributes with the `v-` prefix. Directive attribute values are expected to be **binding expressions**, so the rules about JavaScript expressions mentioned above apply here as well. A directive's job is to reactively apply special behavior to the DOM when the value of its expression changes. Let's review the example we saw in the introduction: +指令 (Directives) 是特殊的带有前缀 `v-` 的特性。指令的值限定为**绑定表达式**,因此上面提到的 JavaScript 表达式及过滤器规则在这里也适用。指令的职责就是当其表达式的值改变时把某些特殊的行为应用到 DOM 上。我们来回头看下“概述”里的例子: ``` htmlHello!
``` -Here, the `v-if` directive would remove/insert the `` element based on the truthiness of the value of the expression `greeting`. +这里 `v-if` 指令将根据表达式 `greeting` 值的真假删除/插入 `
` 元素。
-### Arguments
+### 参数
-Some directives can take an "argument", denoted by a colon after the directive name. For example, the `v-bind` directive is used to reactively update an HTML attribute:
+有些指令可以在其名称后面带一个“参数” (Argument),中间放一个冒号隔开。例如,`v-bind` 指令用于响应地更新 HTML 特性:
``` html
```
-Here `href` is the argument, which tells the `v-bind` directive to bind the element's `href` attribute to the value of the expression `url`. You may have noticed this achieves the same result as an attribute interpolation using `{% raw %}href="{{url}}"{% endraw %}`: that is correct, and in fact, attribute interpolations are translated into `v-bind` bindings internally.
+这里 `href` 是参数,它告诉 `v-bind` 指令将元素的 `href` 特性跟表达式 `url` 的值绑定。可能你已注意到可以用特性插值 `{% raw %}href="{{url}}"{% endraw %}` 获得同样的结果:这样没错,并且实际上在内部特性插值会转为 `v-bind` 绑定。
-Another example is the `v-on` directive, which listens to DOM events:
+另一个例子是 `v-on` 指令,它用于监听 DOM 事件:
``` html
```
-Here the argument is the event name to listen to. We will talk about event handling in more detail too.
+这里参数是被监听的事件的名字。我们也会详细说明事件绑定。
-### Modifiers
+### 修饰符
-Modifiers are special postfixes denoted by a dot, which indicate that a directive should be bound in some special way. For example, the `.literal` modifier tells the directive to interpret its attribute value as a literal string rather than an expression:
+修饰符 (Modifiers) 是以半角句号 `.` 开始的特殊后缀,用于表示指令应当以特殊方式绑定。例如 `.literal` 修饰符告诉指令将它的值解析为一个字面字符串而不是一个表达式:
``` html
```
-Of course, this seems pointless because we can just do `href="/a/b/c"` instead of using a directive. The example here is just for demonstrating the syntax. We will see more practical uses of modifiers later.
+当然,这似乎没有意义,因为我们只需要使用 `href="/a/b/c"` 而不必使用一个指令。这个例子只是为了演示语法。后面我们将看到修饰符更多的实践用法。
-## Shorthands
+## 缩写
-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`:
+`v-` 前缀是一种标识模板中特定的 Vue 特性的视觉暗示。当你需要在一些现有的 HTML 代码中添加动态行为时,这些前缀可以起到很好的区分效果。但你在使用一些常用指令的时候,你会感觉一直这么写实在是啰嗦。而且在构建单页应用([SPA](https://en.wikipedia.org/wiki/Single-page_application) )时,Vue.js 会管理所有的模板,此时 `v-` 前缀也没那么重要了。因此Vue.js 为两个最常用的指令 `v-bind` 和 `v-on` 提供特别的缩写:
-### `v-bind` Shorthand
+### `v-bind` 缩写
``` html
-
+
-
+
-or
-
-
+
-
+
```
-
-### `v-on` Shorthand
+### `v-on` 缩写
``` html
-
+
-
+
```
-They may look a bit different from normal HTML, but all Vue.js supported browsers can parse it correctly, and they do not appear in the final rendered markup. The shorthand syntax is totally optional, but you will likely appreciate it when you learn more about its usage later.
+它们看起来跟“合法”的 HTML 有点不同,但是它们在所有 Vue.js 支持的浏览器中都能被正确地解析,并且不会出现在最终渲染的标记中。缩写语法完全是可选的,不过随着一步步学习的深入,你会庆幸拥有它们。
From af503e71284dcbf26d39b01d69bc58040f42b40e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=B8=81=E4=B8=80=E9=B8=A3?= <315129552@qq.com>
Date: Sat, 13 Aug 2016 21:31:30 +0800
Subject: [PATCH 02/78] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E9=A6=96=E9=A1=B5?=
=?UTF-8?q?=E8=8B=B1=E6=96=87=E4=B8=BA=E4=B8=AD=E6=96=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/CNAME | 1 -
src/support-vuejs/index.md | 26 ++++++++++++-----
themes/vue/layout/index.ejs | 56 ++++++++++++++++++-------------------
themes/vue/layout/page.ejs | 4 +--
4 files changed, 49 insertions(+), 38 deletions(-)
diff --git a/src/CNAME b/src/CNAME
index 79fd262475..e69de29bb2 100644
--- a/src/CNAME
+++ b/src/CNAME
@@ -1 +0,0 @@
-rc.vuejs.org
diff --git a/src/support-vuejs/index.md b/src/support-vuejs/index.md
index 930c1f8353..59982df4c5 100644
--- a/src/support-vuejs/index.md
+++ b/src/support-vuejs/index.md
@@ -1,4 +1,4 @@
-# Support Vue.js Development
+# 支持 Vue.js 的开发
@@ -10,7 +10,12 @@
Donate via PayPal (one time)
-## Current premium sponsors:
+
+
+ 微信打赏
+
+
+## 当前特级赞助商
Reactive Components for Modern Web Interfaces
+数据驱动的组件,为现代化的 Web 界面而生
@@ -49,7 +49,7 @@1 2 @@ -100,44 +100,44 @@ |