Skip to content

Commit 5856735

Browse files
authored
Merge pull request #37 from vuejs/master
update
2 parents 46e08f8 + 9069e36 commit 5856735

File tree

9 files changed

+76
-28
lines changed

9 files changed

+76
-28
lines changed

src/api/index.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ type: api
347347
})
348348
```
349349

350+
<p class="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+
350352
- **See also:** [Reactivity in Depth](/guide/reactivity.html)
351353

352354
### props
@@ -418,6 +420,8 @@ type: api
418420

419421
Computed properties to be mixed into the Vue instance. All getters and setters have their `this` context automatically bound to the Vue instance.
420422

423+
<p class="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+
421425
Computed properties are cached, and only re-computed on reactive dependency changes.
422426

423427
- **Example:**
@@ -458,6 +462,8 @@ type: api
458462

459463
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.
460464

465+
<p class="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+
461467
- **Example:**
462468

463469
```js
@@ -488,16 +494,18 @@ type: api
488494
``` js
489495
var vm = new Vue({
490496
data: {
491-
a: 1
497+
a: 1,
498+
b: 2,
499+
c: 3
492500
},
493501
watch: {
494-
'a': function (val, oldVal) {
502+
a: function (val, oldVal) {
495503
console.log('new: %s, old: %s', val, oldVal)
496504
},
497505
// string method name
498-
'b': 'someMethod',
506+
b: 'someMethod',
499507
// deep watcher
500-
'c': {
508+
c: {
501509
handler: function (val, oldVal) { /* ... */ },
502510
deep: true
503511
}
@@ -506,6 +514,8 @@ type: api
506514
vm.a = 2 // -> new: 2, old: 1
507515
```
508516

517+
<p class="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>
518+
509519
- **See also:** [Instance Methods - vm.$watch](#vm-watch)
510520

511521
## Options / DOM
@@ -559,6 +569,8 @@ type: api
559569

560570
## Options / Lifecycle Hooks
561571

572+
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+
562574
### beforeCreate
563575

564576
- **Type:** `Function`
@@ -829,7 +841,7 @@ type: api
829841

830842
- **Details:**
831843

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.
833845

834846
- **See also:** [Options - data](#data)
835847

src/guide/comparison.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ With that said, we hope you can feel confident in the fairness of the review bel
2626

2727
### Performance Profiles
2828

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).
3030

3131
#### Render Performance
3232

src/guide/index.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ order: 2
66

77
## What is 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](application.html) and [supporting libraries](https://github.com/vuejs/awesome-vue#libraries--plugins).
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).
1010

1111
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).
1212

@@ -51,34 +51,38 @@ In addition to text interpolation, we can also bind element attributes like this
5151

5252
``` html
5353
<div id="app-2">
54-
<span v-bind:id="id">Inspect me</span>
54+
<span v-bind:title="message">
55+
Hover your mouse over me for a few seconds to see my dynamically bound title!
56+
</span>
5557
</div>
5658
```
5759
``` js
5860
var app2 = new Vue({
5961
el: '#app-2',
6062
data: {
61-
id: 'inspect-me'
63+
message: 'You loaded this page on ' + new Date()
6264
}
6365
})
6466
```
6567
{% raw %}
6668
<div id="app-2" class="demo">
67-
<span v-bind:id="id">Inspect me</span>
69+
<span v-bind:title="message">
70+
Hover your mouse over me for a few seconds to see my dynamically bound title!
71+
</span>
6872
</div>
6973
<script>
7074
var app2 = new Vue({
7175
el: '#app-2',
7276
data: {
73-
id: 'inspect-me'
77+
message: 'You loaded this page on ' + new Date()
7478
}
7579
})
7680
</script>
7781
{% endraw %}
7882

79-
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 "bind this element's `id` attribute to the `id` property on the Vue instance."
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."
8084

81-
Use the browser devtools to inspect the element above - you should see that it has the id `inspect-me`. And yes, it would update if you modify `app2.id` in the console.
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.
8286

8387
## Conditionals and Loops
8488

src/guide/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Also available on [jsdelivr](//cdn.jsdelivr.net/vue/{{vue_version}}/vue.js) or [
3636

3737
## NPM
3838

39-
NPM is the recommended installation method when building large scale applications with Vue. It pairs nicely with module bundlers such as [Webpack](http://webpack.github.io/) or [Browserify](http://browserify.org/). Vue also provides accompanying tools for authoring [Single File Components](application.html#Single-File-Components).
39+
NPM is the recommended installation method when building large scale applications with Vue. It pairs nicely with module bundlers such as [Webpack](http://webpack.github.io/) or [Browserify](http://browserify.org/). Vue also provides accompanying tools for authoring [Single File Components](single-file-components.html).
4040

4141
``` bash
4242
# latest stable

src/guide/instance.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ vm.$watch('a', function (newVal, oldVal) {
7373
})
7474
```
7575

76+
<p class="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>
77+
7678
Consult the [API reference](/api) for the full list of instance properties and methods.
7779

7880
## Instance Lifecycle Hooks

src/guide/migration.md

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ Most use cases of mutating a prop can be replaced by one of these options:
332332

333333
### Props on a Root Instance <sup>deprecated</sup>
334334

335-
On root Vue instances (i.e. instances created with `new Vue({ ... })`), you must use `propsData` instead instead of `props`.
335+
On root Vue instances (i.e. instances created with `new Vue({ ... })`), you must use `propsData` instead of `props`.
336336

337337
{% raw %}
338338
<div class="upgrade-path">
@@ -653,7 +653,7 @@ Directives have a greatly reduced scope of responsibility: they are now only use
653653
Some of the most notable differences include:
654654

655655
- Directives no longer have instances. This means there's no more `this` inside directive hooks. Instead, they receive everything they might need as arguments. If you really must persist state across hooks, you can do so on `el`.
656-
- Options such as `acceptStatement`, `deep`, `priority`, etc are all deprecated.
656+
- Options such as `acceptStatement`, `deep`, `priority`, etc are all deprecated. To replace `twoWay` directives, see [this example](#Two-Way-Filters-deprecated).
657657
- Some of the current hooks have different behavior and there are also a couple new hooks.
658658

659659
Fortunately, since the new directives are much simpler, you can master them more easily. Read the new [Custom Directives guide](custom-directive.html) to learn more.
@@ -665,6 +665,29 @@ Fortunately, since the new directives are much simpler, you can master them more
665665
</div>
666666
{% endraw %}
667667

668+
### Directive `.literal` Modifier <sup>deprecated</sup>
669+
670+
The `.literal` modifier has been removed, as the same can be easily achieved by just providing a string literal as the value.
671+
672+
For example, you can update:
673+
674+
``` js
675+
<p v-my-directive.literal="foo bar baz"></p>
676+
```
677+
678+
to just:
679+
680+
``` html
681+
<p v-my-directive="'foo bar baz'"></p>
682+
```
683+
684+
{% raw %}
685+
<div class="upgrade-path">
686+
<h4>Upgrade Path</h4>
687+
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of the `.literal` modifier on a directive.</p>
688+
</div>
689+
{% endraw %}
690+
668691
## Transitions
669692

670693
### `transition` Attribute <sup>deprecated</sup>
@@ -702,6 +725,10 @@ If you need to stagger list transitions, you can control timing by setting and a
702725

703726
## Events
704727

728+
### `events` option <sup>deprecated</sup>
729+
730+
The `events` option has been deprecated. Event handlers should now be registered in the `created` hook instead. Check out the [`$dispatch` and `$broadcast` migration guide](#dispatch-and-broadcast-deprecated) for a detailed example.
731+
705732
### `Vue.directive('on').keyCodes` <sup>deprecated</sup>
706733

707734
The new, more concise way to configure `keyCodes` is through`Vue.config.keyCodes`. For example:
@@ -1016,32 +1043,32 @@ In many cases though, you'll still run into strange behavior (e.g. `0.035.toFixe
10161043

10171044
### Two-Way Filters <sup>deprecated</sup>
10181045

1019-
Some users have enjoyed using two-way filters with `v-model` to create interesting inputs with very little code. While seemingly simple however, two-way filters can also hide a great deal of complexity - and even encourage poor UX by delaying state updates. Instead, components are recommended as a more explicit and feature-rich way of creating custom inputs.
1046+
Some users have enjoyed using two-way filters with `v-model` to create interesting inputs with very little code. While _seemingly_ simple however, two-way filters can also hide a great deal of complexity - and even encourage poor UX by delaying state updates. Instead, components wrapping an input are recommended as a more explicit and feature-rich way of creating custom inputs.
10201047

1021-
We'll now walk through an example of a filter provided by the community and offer tips for how to migrate away from two-way filters. Here's a simple currency filter:
1048+
As an example, we'll now walk the migration of a two-way currency filter:
10221049

1023-
<iframe width="100%" height="300" src="https://jsfiddle.net/chrisvfritz/6744xnjk/embedded/result,html,js" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
1050+
<iframe width="100%" height="300" src="https://jsfiddle.net/chrisvfritz/6744xnjk/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
10241051

1025-
It mostly works well, but the delayed state updates can cause strange behavior. For example, try entering `99.999` into one of those inputs. When the input loses focus, its value will update to `$100.00`. When looking at the calculated total however, you'll see that `99.999` is what's stored in our data. The version of reality that the user sees is out of sync!
1052+
It mostly works well, but the delayed state updates can cause strange behavior. For example, click on the `Result` tab and try entering `9.999` into one of those inputs. When the input loses focus, its value will update to `$10.00`. When looking at the calculated total however, you'll see that `9.999` is what's stored in our data. The version of reality that the user sees is out of sync!
10261053

1027-
To start transitioning towards a more robust solution using Vue 2.0, let's first refactor this filter into a component that uses it:
1054+
To start transitioning towards a more robust solution using Vue 2.0, let's first wrap this filter in a new `<currency-input>` component:
10281055

1029-
<iframe width="100%" height="300" src="https://jsfiddle.net/chrisvfritz/g7osemrx/embedded/result,html,js" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
1056+
<iframe width="100%" height="300" src="https://jsfiddle.net/chrisvfritz/943zfbsh/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
10301057

1031-
This allows us add behavior that wasn't possible with a filter alone, such as selecting the content of an input on focus. Now the next step will be to extract the business logic from the filter:
1058+
This allows us add behavior that a filter alone couldn't encapsulate, such as selecting the content of an input on focus. Now the next step will be to extract the business logic from the filter. Below, we pull everything out into an external [`currencyValidator` object](https://gist.github.com/chrisvfritz/5f0a639590d6e648933416f90ba7ae4e):
10321059

1033-
<iframe width="100%" height="300" src="https://jsfiddle.net/chrisvfritz/j4xtb20e/embedded/result,html,js" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
1060+
<iframe width="100%" height="300" src="https://jsfiddle.net/chrisvfritz/9c32kev2/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
10341061

10351062
This increased modularity not only makes it easier to migrate to Vue 2, but also allows currency parsing and formatting to be:
10361063

10371064
- unit tested in isolation from your Vue code
10381065
- used by other parts of your application, such as to validate the payload to an API endpoint
10391066

1040-
Having this validator extracted out, we can also more comfortably build it up into a more robust solution. We've now eliminated the state quirks and have even made it impossible for users to enter anything wrong, similar to what the browser's native number input tries to do.
1067+
Having this validator extracted out, we've also more comfortably built it up into a more robust solution. The state quirks have been eliminated and it's actually impossible for users to enter anything wrong, similar to what the browser's native number input tries to do.
10411068

10421069
We're still limited however, by filters and by Vue 1.0 in general, so let's complete the upgrade to Vue 2.0:
10431070

1044-
<iframe width="100%" height="300" src="https://jsfiddle.net/chrisvfritz/r4e49aLs/embedded/result,html,js" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
1071+
<iframe width="100%" height="300" src="https://jsfiddle.net/chrisvfritz/1oqjojjx/embedded/js,html,result" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
10451072

10461073
You may notice that:
10471074

@@ -1127,7 +1154,7 @@ When used together with `<transition>`, make sure to nest it inside:
11271154
Interpolation within attributes is no longer valid. For example:
11281155

11291156
``` html
1130-
<button v-bind:class="btn btn-{{ size }}"></button>
1157+
<button class="btn btn-{{ size }}"></button>
11311158
```
11321159

11331160
Should either be updated to use an inline expression:

src/guide/render-function.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ One thing to note: similar to how `v-bind:class` and `v-bind:style` have special
160160
nativeOn: {
161161
click: this.nativeClickHandler
162162
},
163+
// The name of a slot if the child of a component
164+
slot: 'name-of-slot'
163165
// Other special top-level properties
164166
key: 'myKey',
165167
ref: 'myRef'

src/guide/unit-testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ order: 22
66

77
## Setup and Tooling
88

9-
Anything compatible with a module-based build system will work, but if you're looking for a specific recommendation, try the [Karma](http://karma-runner.github.io/0.12/index.html) test runner. It has a lot of community plugins, including support for [Webpack](https://github.com/webpack/karma-webpack) and [Browserify](https://github.com/Nikku/karma-browserify). For detailed setup, please refer to each project's respective documentation, though these example Karma configurations for [Webpack](https://github.com/vuejs/vue-loader-example/blob/master/build/karma.conf.js) and [Browserify](https://github.com/vuejs/vueify-example/blob/master/karma.conf.js) may help you get started.
9+
Anything compatible with a module-based build system will work, but if you're looking for a specific recommendation, try the [Karma](http://karma-runner.github.io) test runner. It has a lot of community plugins, including support for [Webpack](https://github.com/webpack/karma-webpack) and [Browserify](https://github.com/Nikku/karma-browserify). For detailed setup, please refer to each project's respective documentation, though these example Karma configurations for [Webpack](https://github.com/vuejs/vue-loader-example/blob/master/build/karma.conf.js) and [Browserify](https://github.com/vuejs/vueify-example/blob/master/karma.conf.js) may help you get started.
1010

1111
## Simple Assertions
1212

themes/vue/source/css/_common.styl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ body
77
-webkit-font-smoothing antialiased
88
-moz-osx-font-smoothing grayscale
99
color $medium
10+
background-color white
1011
margin 0
1112

1213
a

0 commit comments

Comments
 (0)