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
* master:
Revert "Master" (#462)
Master (#460)
Update link to Karma (#458)
Explicitly note on `events` opt deprecation (fixes#436) (#453)
remove wording about not including a benchmark from the react team
Set the background-color to white. (#452)
fix capitalizion typo in migration guide
add literal modifier for directives to migration guide
fix typo in interpolation within attributes in migration guide
update dynamic binding example in guide intro
add named slot to render function guide
add warnings about using arrow functions on instance properties (#448)
fix links to single-file components - fixes#446
add note about two-way directives, linking to two-way filters example
update two-filters example in migration guide
Same word used multiple times in a sentence (#444)
improve $data instance property API docs (#445)
# Conflicts:
# src/guide/index.md
# src/guide/installation.md
# src/guide/instance.md
# src/guide/render-function.md
# src/guide/unit-testing.md
Copy file name to clipboardExpand all lines: src/api/index.md
+17-5Lines changed: 17 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -347,6 +347,8 @@ type: api
347
347
})
348
348
```
349
349
350
+
<pclass="tip">Note that __you should not use an arrow function with the `data` property__ (e.g. `data: () => { return { a: this.myProp }}`). The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect and `this.myProp` will be undefined.</p>
351
+
350
352
-**See also:**[Reactivity in Depth](/guide/reactivity.html)
351
353
352
354
### props
@@ -418,6 +420,8 @@ type: api
418
420
419
421
Computed properties to be mixed into the Vue instance. All getters and setters have their `this` context automatically bound to the Vue instance.
420
422
423
+
<pclass="tip">Note that __you should not use an arrow function to define a computed property__ (e.g. `aDouble: () => this.a * 2`). The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect and `this.a` will be undefined.</p>
424
+
421
425
Computed properties are cached, and only re-computed on reactive dependency changes.
422
426
423
427
-**Example:**
@@ -458,6 +462,8 @@ type: api
458
462
459
463
Methods to be mixed into the Vue instance. You can access these methods directly on the VM instance, or use them in directive expressions. All methods will have their `this` context automatically bound to the Vue instance.
460
464
465
+
<pclass="tip">Note that __you should not use an arrow function to define a method__ (e.g. `plus: () => this.a++`). The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect and `this.a` will be undefined.</p>
466
+
461
467
-**Example:**
462
468
463
469
```js
@@ -488,16 +494,18 @@ type: api
488
494
```js
489
495
var vm =newVue({
490
496
data: {
491
-
a:1
497
+
a:1,
498
+
b:2,
499
+
c:3
492
500
},
493
501
watch: {
494
-
'a':function (val, oldVal) {
502
+
a:function (val, oldVal) {
495
503
console.log('new: %s, old: %s', val, oldVal)
496
504
},
497
505
// string method name
498
-
'b':'someMethod',
506
+
b:'someMethod',
499
507
// deep watcher
500
-
'c': {
508
+
c: {
501
509
handler:function (val, oldVal) { /* ... */ },
502
510
deep:true
503
511
}
@@ -506,6 +514,8 @@ type: api
506
514
vm.a=2// -> new: 2, old: 1
507
515
```
508
516
517
+
<pclass="tip">Note that __you should not use an arrow function to define a watcher__ (e.g. `searchQuery: newValue => this.updateAutocomplete(newValue)`). The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect and `this.updateAutocomplete` will be undefined.</p>
All lifecycle hooks automatically have their `this` context bound to the instance, so that you can access data, computed properties, and methods. This means __you should not use an arrow function to define a lifecycle method__ (e.g. `created: () => this.fetchTodos()`). The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect and `this.fetchTodos` will be undefined.
573
+
562
574
### beforeCreate
563
575
564
576
-**Type:**`Function`
@@ -829,7 +841,7 @@ type: api
829
841
830
842
-**Details:**
831
843
832
-
The data object that the Vue instance is observing. You can swap it with a new object. The Vue instance proxies access to the properties on its data object.
844
+
The data object that the Vue instance is observing. The Vue instance proxies access to the properties on its data object.
Copy file name to clipboardExpand all lines: src/guide/comparison.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ With that said, we hope you can feel confident in the fairness of the review bel
26
26
27
27
### Performance Profiles
28
28
29
-
In every real-world scenario that we've tested so far, Vue outperforms React by a fair margin (usually at least 20-50% faster, though in some cases much more than that). We could now link to benchmarks - but frankly, all benchmarks are flawed in some way and very few resemble what you'd write in a real application. Instead, let's break it down.
29
+
In every real-world scenario that we've tested so far, Vue outperforms React by a fair margin. If your eyebrows are raising right now, read further. We'll breakdown why (and even include a benchmark developed in collaboration with the React team).
Copy file name to clipboardExpand all lines: src/guide/index.md
+47-57Lines changed: 47 additions & 57 deletions
Original file line number
Diff line number
Diff line change
@@ -1,32 +1,28 @@
1
1
---
2
-
title: 起步
2
+
title: 介绍
3
3
type: guide
4
4
order: 2
5
5
---
6
6
7
-
## Vue.js是什么?
7
+
## What is Vue.js?
8
8
9
-
Vue.js(读音 /vjuː/, 类似于**view**)是一个构建数据驱动的 web 界面的库。Vue.js 的目标是通过尽可能简单的 API 实现**响应的数据绑定**和**组合的视图组件**。
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).
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).
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.
16
16
17
-
尝试 Vue.js 最简单的方法是使用 [JSFiddle Hello World example](https://jsfiddle.net/chrisvfritz/4tpzm3e1/) 。在浏览器新标签页中打开它,跟着我们查看一些基础示例。如果你喜欢用包管理器下载/安装,查看[安装](/guide/installation.html)教程。
17
+
## Declarative Rendering
18
18
19
-
## 声明式渲染
19
+
At the core of Vue.js is a system that enables us to declaratively render data to the DOM using straightforward template syntax:
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.
54
49
55
-
除了文本插值,也可以绑定元素属性像这样:
50
+
In addition to text interpolation, we can also bind element attributes like this:
56
51
57
52
```html
58
53
<divid="app-2">
59
-
<spanv-bind:id="id">Inspect me</span>
54
+
<spanv-bind:title="message">
55
+
Hover your mouse over me for a few seconds to see my dynamically bound title!
56
+
</span>
60
57
</div>
61
58
```
62
-
63
59
```js
64
60
var app2 =newVue({
65
61
el:'#app-2',
66
62
data: {
67
-
id:'inspect-me'
63
+
message:'You loaded this page on '+newDate()
68
64
}
69
65
})
70
66
```
71
-
72
67
{% raw %}
73
68
<divid="app-2"class="demo">
74
-
<spanv-bind:id="id">Inspect me</span>
69
+
<spanv-bind:title="message">
70
+
Hover your mouse over me for a few seconds to see my dynamically bound title!
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."
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.
89
86
90
-
## 条件和循环
87
+
## Conditionals and Loops
91
88
92
-
切换显示元素也是相当简单:
89
+
It's quite simple to toggle the presence of an element, too:
93
90
94
91
```html
95
92
<divid="app-3">
@@ -120,22 +117,21 @@ var app3 = new Vue({
120
117
</script>
121
118
{% endraw %}
122
119
123
-
在控制台设置 `app3.seen = false`,可以看到消息消失了。
120
+
Go ahead and enter `app3.seen = false` in the console. You should see the message disappear.
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.
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:
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.
222
215
223
-
Vue还提供了`v-model`指令 很轻巧地实现输入和应用状态间的双向数据绑定。
216
+
Vue also provides the `v-model`directive that makes two-way binding between form input and app state a breeze:
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:
259
250
260
-

251
+

261
252
262
-
Vue中,一个组件基本上是一个预定义了设置的Vue实例。在Vue注册组件也很简单:
253
+
In Vue, a component is essentially a Vue instance with pre-defined options. Registering a component in Vue is straightforward:
263
254
264
255
```js
265
256
// Define a new component called todo-item
@@ -268,7 +259,7 @@ Vue.component('todo-item', {
268
259
})
269
260
```
270
261
271
-
现在可以在另一个组件模板中使用它:
262
+
Now you can compose it in another component's template:
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):
284
275
285
276
```js
286
277
Vue.component('todo-item', {
@@ -292,7 +283,7 @@ Vue.component('todo-item', {
292
283
})
293
284
```
294
285
295
-
现在我们可以通过`v-bind`传递todo进入每个可重用的组件中:
286
+
Now we can pass the todo into each repeated component using `v-bind`:
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.
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:
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:
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.
365
354
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.
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!
Copy file name to clipboardExpand all lines: src/guide/instance.md
+4-1Lines changed: 4 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -77,7 +77,10 @@ vm.$watch('a', function (newVal, oldVal) {
77
77
})
78
78
```
79
79
80
-
参考 [API 文档](/api)查看全部的实例属性与方法。
80
+
81
+
<pclass="tip">Note that __you should not use arrow functions on an instance property or callback__ (e.g. `vm.$watch('a', newVal => this.myMethod())`). The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect and `this.myMethod` will be undefined.</p>
82
+
83
+
Consult the [API reference](/api) for the full list of instance properties and methods.
0 commit comments