Skip to content

Commit 5485e02

Browse files
committed
translate index.md - ArticleID: 2
1 parent 9da82a6 commit 5485e02

File tree

1 file changed

+52
-64
lines changed

1 file changed

+52
-64
lines changed

src/guide/index.md

Lines changed: 52 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,33 @@ type: guide
44
order: 2
55
---
66

7-
## What is Vue.js?
7+
## Vue.js 是什么
88

9-
Vue (pronounced /vjuː/, like **view**) is a **progressive framework** for building user interfaces. Unlike other monolithic frameworks, Vue is designed from the ground up to be incrementally adoptable. The core library is focused on the view layer only, and is very easy to pick up and integrate with other libraries or existing projects. On the other hand, Vue is also perfectly capable of powering sophisticated Single-Page Applications when used in combination with [modern tooling](single-file-components.html) and [supporting libraries](https://github.com/vuejs/awesome-vue#libraries--plugins).
9+
Vue.js(读音 /vjuː/, 类似于 **view**)是一个构建用户界面的渐进式框架。与其他单层框架( monolithic frameworks)不同的是,Vue 被设计成从底层向上可以被增量式的采用。Vue 的核心库只关注视图层,并且非常容易学习,非常容易与其它库或已有项目整合。另一方面,Vue 完全有能力驱动采用[现代化工具](//vuejs.org/guide/application.html)[Vue生态系统支持的库](//github.com/vuejs/awesome-vue#libraries--plugins)开发的复杂单页应用。
1010

11-
If you are an experienced frontend developer and want to know how Vue compares to other libraries/frameworks, check out the [Comparison with Other Frameworks](comparison.html).
1211

13-
## Getting Started
12+
Vue.js 的目标是通过尽可能简单的 API 实现**响应的数据绑定****组合的视图组件**
1413

15-
The easiest way to try out Vue.js is using the [JSFiddle Hello World example](https://jsfiddle.net/chrisvfritz/4tpzm3e1/). 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.
14+
如果你是有经验的前端开发者,想知道 Vue.js 与其它库/框架的区别,查看[对比其它框架](//vuejs.org/guide/comparison.html)
1615

17-
## Declarative Rendering
16+
## 起步
1817

19-
At the core of Vue.js is a system that enables us to declaratively render data to the DOM using straightforward template syntax:
18+
尝试 Vue.js 最简单的方法是使用 [JSFiddle Hello World 例子](//jsfiddle.net/chrisvfritz/4tpzm3e1/)。请在浏览器新标签页中打开它,跟着我们查看一些基础示例。如果你喜欢用包管理器下载/安装,查看[安装](//vuejs.org/guide/installation.html)教程。
19+
20+
## 声明式渲染
21+
22+
Vue.js 的核心是一个允许你采用简洁的模板语法来声明式的将数据渲染进DOM的系统:
2023

2124
``` html
2225
<div id="app">
2326
{{ message }}
2427
</div>
2528
```
2629
``` js
27-
var app = new Vue({
30+
new Vue({
2831
el: '#app',
2932
data: {
30-
message: 'Hello Vue!'
33+
message: 'Hello Vue.js!'
3134
}
3235
})
3336
```
@@ -45,22 +48,20 @@ var app = new Vue({
4548
</script>
4649
{% endraw %}
4750

48-
We have already created our very first Vue app! This looks pretty similar to just rendering a string template, but Vue has done a lot of work under the hood. The data and the DOM are now linked, and everything is now **reactive**. How do we know? Just open up your browser's JavaScript console and set `app.message` to a different value. You should see the rendered example above update accordingly.
51+
我们已经生成了我们的第一个 Vue 应用!看起来这跟单单渲染一个字符串模板非常类似,但是 Vue.js 在背后做了大量工作。现在数据和DOM已经被绑定在一起,所有的元素都是**响应式的(reactive**。我们如何知道?打开你的浏览器的控制台,并修改 `app.message`,你将看到上例相应地更新。
4952

50-
In addition to text interpolation, we can also bind element attributes like this:
53+
除了绑定插入的文本内容,我们还可以采用这样的方式绑定 DOM 元素属性:
5154

5255
``` html
5356
<div id="app-2">
54-
<span v-bind:title="message">
55-
Hover your mouse over me for a few seconds to see my dynamically bound title!
56-
</span>
57+
<span v-bind:id="id">Inspect me</span>
5758
</div>
5859
```
5960
``` js
6061
var app2 = new Vue({
6162
el: '#app-2',
6263
data: {
63-
message: 'You loaded this page on ' + new Date()
64+
id: 'inspect-me'
6465
}
6566
})
6667
```
@@ -80,20 +81,19 @@ var app2 = new Vue({
8081
</script>
8182
{% endraw %}
8283

83-
Here we are encountering something new. The `v-bind` attribute you are seeing is called a **directive**. Directives are prefixed with `v-` to indicate that they are special attributes provided by Vue, and as you may have guessed, they apply special reactive behavior to the rendered DOM. Here it is basically saying "keep this element's `title` attribute up-to-date with the `message` property on the Vue instance."
84+
这里我们遇到新东西。你看到的 `v-bind` 特性被称为**指令**。指令带有前缀 `v-`,以指示它们是 Vue.js 提供的特殊特性。并且如你所想象的,它们会对绑定的目标元素添加响应式的特殊行为。这个指令的简单含义是说:将该元素的 id 属性绑定到 Vue 实例的 id 属性上。
8485

85-
If you open up your JavaScript console again and enter `app2.message = 'some new message'`, you'll once again see that the bound HTML - in this case the `title` attribute - has been updated.
86+
用浏览器的开发者工具去监测以上元素 - 你会发现 这个元素的 id 为 `inspect-me`。是的,如果你在控制台里更改`app2.id`,那么该元素的 id 也会随之更新。
8687

87-
## Conditionals and Loops
88+
## 条件与循环
8889

89-
It's quite simple to toggle the presence of an element, too:
90+
控制切换一个元素的显示也相当简单:
9091

9192
``` html
9293
<div id="app-3">
9394
<p v-if="seen">Now you see me</p>
9495
</div>
9596
```
96-
9797
``` js
9898
var app3 = new Vue({
9999
el: '#app-3',
@@ -117,11 +117,11 @@ var app3 = new Vue({
117117
</script>
118118
{% endraw %}
119119

120-
Go ahead and enter `app3.seen = false` in the console. You should see the message disappear.
120+
继续在控制台设置 `app3.seen = false`,你会发现 “Now you see me” 消失了。
121121

122-
This example demonstrates that we can bind data to not only text and attributes, but also the **structure** of the DOM. Moreover, Vue also provides a powerful transition effect system that can automatically apply [transition effects](transitions.html) when elements are inserted/updated/removed by Vue.
122+
这个例子演示了我们不仅可以绑定 DOM 文本到数据,也可以绑定 DOM **结构** 到数据。而且,Vue.js 也提供一个强大的过渡效果系统,可以在 Vue 插入/删除元素时自动应用[过渡效果](//vuejs.org/guide/transitions.html)
123123

124-
There are quite a few other directives, each with its own special functionality. For example, the `v-for` directive can be used for displaying a list of items using the data from an Array:
124+
也有一些其它指令,每个都有特殊的功能。例如, `v-for` 指令可以绑定数据到数据来渲染一个列表:
125125

126126
``` html
127127
<div id="app-4">
@@ -144,6 +144,7 @@ var app4 = new Vue({
144144
}
145145
})
146146
```
147+
147148
{% raw %}
148149
<div id="app-4" class="demo">
149150
<ol>
@@ -166,11 +167,11 @@ var app4 = new Vue({
166167
</script>
167168
{% endraw %}
168169

169-
In the console, enter `app4.todos.push({ text: 'New item' })`. You should see a new item appended to the list.
170+
在控制台里,输入`app4.todos.push({ text: 'New item' })`。你会发现列表中多了一栏新内容。
170171

171-
## Handling User Input
172+
## 处理用户输入
172173

173-
To let users interact with your app, we can use the `v-on` directive to attach event listeners that invoke methods on our Vue instances:
174+
为了让用户和你的应用进行互动,我们可以用 `v-on` 指令绑定一个监听事件用于调用我们 Vue 实例中定义的方法:
174175

175176
``` html
176177
<div id="app-5">
@@ -191,6 +192,7 @@ var app5 = new Vue({
191192
}
192193
})
193194
```
195+
194196
{% raw %}
195197
<div id="app-5" class="demo">
196198
<p>{{ message }}</p>
@@ -211,9 +213,9 @@ var app5 = new Vue({
211213
</script>
212214
{% endraw %}
213215

214-
Note in the method we simply update the state of our app without touching the DOM - all DOM manipulations are handled by Vue, and the code you write is focused on the underlying logic.
216+
`reverseMessage` 方法中,我们在没有接触 DOM 的情况下更新了应用的状态 - 所有的 DOM 操作都由 Vue 来处理,你写的代码只需要关注基本逻辑。
215217

216-
Vue also provides the `v-model` directive that makes two-way binding between form input and app state a breeze:
218+
Vue 也提供了 `v-model` 指令,它使得在表单输入和应用状态中做双向数据绑定变得非常轻巧。
217219

218220
``` html
219221
<div id="app-6">
@@ -229,6 +231,7 @@ var app6 = new Vue({
229231
}
230232
})
231233
```
234+
232235
{% raw %}
233236
<div id="app-6" class="demo">
234237
<p>{{ message }}</p>
@@ -244,70 +247,55 @@ var app6 = new Vue({
244247
</script>
245248
{% endraw %}
246249

247-
## Composing with Components
250+
## 用组件构建(应用)
248251

249-
The component system is another important concept in Vue, because it's an abstraction that allows us to build large-scale applications composed of small, self-contained, and often reusable components. If we think about it, almost any type of application interface can be abstracted into a tree of components:
252+
组件系统是 Vue.js 另一个重要概念,因为它提供了一种抽象,让我们可以用独立可复用的小组件来构建大型应用。如果我们考虑到这点,几乎任意类型的应用的界面都可以抽象为一个组件树:
250253

251254
![Component Tree](/images/components.png)
252255

253-
In Vue, a component is essentially a Vue instance with pre-defined options. Registering a component in Vue is straightforward:
256+
Vue 里,一个组件实质上是一个拥有预定义选项的一个 Vue 实例:
254257

255258
``` js
256-
// Define a new component called todo-item
257-
Vue.component('todo-item', {
259+
Vue.component('todo', {
258260
template: '<li>This is a todo</li>'
259261
})
260262
```
261263

262-
Now you can compose it in another component's template:
264+
现在你可以另一个组件模板中写入它:
263265

264266
``` html
265267
<ul>
266-
<!--
267-
Create an instance of the todo-item component
268-
for each todo in a todos array
269-
-->
270-
<todo-item v-for="todo in todos"></todo-item>
268+
<todo v-for="todo in todos"></todo>
271269
</ul>
272270
```
273271

274-
But this would render the same text for every todo, which is not super interesting. We should be able to pass data from the parent scope into child components. Let's modify the component definition to make it accept a [prop](/guide/components.html#Props):
272+
但是这样会为每个 todo 渲染同样的文本,这看起来并不是很6。我们应该将数据从父作用域传到子组件。让我们来修改一下组件的定义,使得它能够接受一个 [`prop`](//vuejs.org/guide/components.html#Props) 字段:
275273

276274
``` js
277-
Vue.component('todo-item', {
278-
// The todo-item component now accepts a
279-
// "prop", which is like a custom attribute.
280-
// This prop is called todo.
275+
Vue.component('todo', {
281276
props: ['todo'],
282277
template: '<li>{{ todo.text }}</li>'
283278
})
284279
```
285280

286-
Now we can pass the todo into each repeated component using `v-bind`:
281+
现在,我们可以使用 `v-bind` 指令将 todo 传到每一个重复的组件中:
287282

288283
``` html
289284
<div id="app-7">
290285
<ol>
291-
<!--
292-
Now we provide each todo-item with the todo object
293-
it's representing, so that its content can be dynamic
294-
-->
295-
<todo-item v-for="todo in todos" v-bind:todo="todo"></todo-item>
286+
<todo v-for="todo in todos" v-bind:todo="todo"></todo>
296287
</ol>
297288
</div>
298-
```
289+
```
299290
``` js
300291
var app7 = new Vue({
301292
el: '#app-7',
302293
data: {
303-
todos: [
304-
{ text: 'Learn JavaScript' },
305-
{ text: 'Learn Vue' },
306-
{ text: 'Build something awesome' }
307-
]
294+
todos: [/* ... */]
308295
}
309296
})
310297
```
298+
311299
{% raw %}
312300
<div id="app-7" class="demo">
313301
<ol>
@@ -332,9 +320,9 @@ var app7 = new Vue({
332320
</script>
333321
{% endraw %}
334322

335-
This is just a contrived example, but we have managed to separate our app into two smaller units, and the child is reasonably well-decoupled from the parent via the props interface. We can now further improve our `<todo-item>` component with more complex template and logic without affecting the parent app.
323+
这只是一个人为的例子,但是我们已经将我们的应用分割成了两小的单元,子元素通过 `props` 接口实现了与父亲元素很好的解耦。我们现在可以在不影响到父亲应用的基础上,进一步为我们的 `todo` 组件改进更多复杂的模板和逻辑。
336324

337-
In a large application, it is necessary to divide the whole app into components to make development manageable. We will talk a lot more about components [later in the guide](/guide/components.html), but here's an (imaginary) example of what an app's template might look like with components:
325+
在一个大型应用中,为了使得开发过程可控,有必要将应用整体分割成一个个的组件。在[后面的教程](//vuejs.org/guide/components.html)中我们将详述组件,不过这里有一个(假想)的例子,看看使用了组件的应用模板是什么样的:
338326

339327
``` html
340328
<div id="app">
@@ -346,14 +334,14 @@ In a large application, it is necessary to divide the whole app into components
346334
</div>
347335
```
348336

349-
### Relation to Custom Elements
337+
## 与自定义元素的关系
350338

351-
You may have noticed that Vue components are very similar to **Custom Elements**, which are part of the [Web Components Spec](http://www.w3.org/wiki/WebComponents/). That's because Vue's component syntax is loosely modeled after the spec. For example, Vue components implement the [Slot API](https://github.com/w3c/webcomponents/blob/gh-pages/proposals/Slots-Proposal.md) and the `is` special attribute. However, there are a few key differences:
339+
你可能已经注意到 Vue.js 组件非常类似于**自定义元素**——它是 [Web 组件规范](//www.w3.org/wiki/WebComponents/)的一部分。实际上 Vue.js 的组件语法参考了该规范。例如 Vue 组件实现了 [Slot API](//github.com/w3c/webcomponents/blob/gh-pages/proposals/Slots-Proposal.md) `is` 特性。但是,有几个关键的不同:
352340

353-
1. The Web Components Spec is still in draft status, and is not natively implemented in every browser. In comparison, Vue components don't require any polyfills and work consistently in all supported browsers (IE9 and above). When needed, Vue components can also be wrapped inside a native custom element.
341+
1. Web 组件规范仍然远未完成,并且没有浏览器实现。相比之下,Vue.js 组件不需要任何补丁,并且在所有支持的浏览器(IE9 及更高版本)之下表现一致。必要时,Vue.js 组件也可以放在原生自定义元素之内。
354342

355-
2. Vue components provide important features that are not available in plain custom elements, most notably cross-component data flow, custom event communication and build tool integrations.
343+
2. Vue.js 组件提供了原生自定义元素所不具备的一些重要功能,比如组件间的数据流,自定义事件系统,以及动态的、带特效的组件替换。
356344

357-
## Ready for More?
345+
## 准备好探索更广阔的世界了?
358346

359-
We've just briefly introduced the most basic features of Vue.js core - the rest of this guide will cover them and other advanced features with much finer details, so make sure to read through it all!
347+
我们刚才简单介绍了 Vue.js 核心的一些最基本的特征 - 本指南的其余部分将用更详尽的篇幅去描述其他的一些高级特性,所以一定要阅读完所有的内容哦!

0 commit comments

Comments
 (0)