Skip to content

Commit 2355fbc

Browse files
authored
Reorganize sidebar and some content; cannibalize reactivity page (#1086)
* reorganize sidebar and some content; cannibalize reactivity page * Fix typo in instance.md * Fix typo in instance.md * Change errorMessage: null to error: null in instance.md * Fix typo in reactivity.md.hidden * remove redundant note about filters
1 parent cd6f6c0 commit 2355fbc

31 files changed

+523
-292
lines changed

src/images/logged-proxied-data.png

58.6 KB
Loading

src/v2/api/index.md

+33-11
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ if (version === 2) {
436436
var vm = new Vue({
437437
data: data
438438
})
439-
vm.a // -> 1
440-
vm.$data === data // -> true
439+
vm.a // => 1
440+
vm.$data === data // => true
441441

442442
// must use function when in Vue.extend()
443443
var Component = Vue.extend({
@@ -545,10 +545,10 @@ if (version === 2) {
545545
}
546546
}
547547
})
548-
vm.aPlus // -> 2
548+
vm.aPlus // => 2
549549
vm.aPlus = 3
550-
vm.a // -> 2
551-
vm.aDouble // -> 4
550+
vm.a // => 2
551+
vm.aDouble // => 4
552552
```
553553

554554
- **See also:** [Computed Properties](../guide/computed.html)
@@ -610,7 +610,7 @@ if (version === 2) {
610610
}
611611
}
612612
})
613-
vm.a = 2 // -> new: 2, old: 1
613+
vm.a = 2 // => new: 2, old: 1
614614
```
615615

616616
<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>
@@ -744,6 +744,17 @@ if (version === 2) {
744744

745745
Called after the instance has just been mounted where `el` is replaced by the newly created `vm.$el`. If the root instance is mounted to an in-document element, `vm.$el` will also be in-document when `mounted` is called.
746746

747+
Note that `mounted` does **not** guarantee that all child components have also been mounted. If you want to wait until the entire view has been rendered, you can use [vm.$nextTick](#vm-nextTick) inside of `mounted`:
748+
749+
``` js
750+
mounted: function () {
751+
this.$nextTick(function () {
752+
// Code that will run only after the
753+
// entire view has been rendered
754+
})
755+
}
756+
```
757+
747758
**This hook is not called during server-side rendering.**
748759
749760
- **See also:** [Lifecycle Diagram](../guide/instance.html#Lifecycle-Diagram)
@@ -772,6 +783,17 @@ if (version === 2) {
772783
773784
The component's DOM will have been updated when this hook is called, so you can perform DOM-dependent operations here. However, in most cases you should avoid changing state inside the hook. To react to state changes, it's usually better to use a [computed property](#computed) or [watcher](#watch) instead.
774785
786+
Note that `updated` does **not** guarantee that all child components have also been re-rendered. If you want to wait until the entire view has been re-rendered, you can use [vm.$nextTick](#vm-nextTick) inside of `updated`:
787+
788+
``` js
789+
updated: function () {
790+
this.$nextTick(function () {
791+
// Code that will run only after the
792+
// entire view has been re-rendered
793+
})
794+
}
795+
```
796+
775797
**This hook is not called during server-side rendering.**
776798
777799
- **See also:** [Lifecycle Diagram](../guide/instance.html#Lifecycle-Diagram)
@@ -892,8 +914,8 @@ if (version === 2) {
892914
created: function () { console.log(2) },
893915
mixins: [mixin]
894916
})
895-
// -> 1
896-
// -> 2
917+
// => 1
918+
// => 2
897919
```
898920
899921
- **See also:** [Mixins](../guide/mixins.html)
@@ -953,7 +975,7 @@ if (version === 2) {
953975
var Child = {
954976
inject: ['foo'],
955977
created () {
956-
console.log(this.foo) // -> "bar"
978+
console.log(this.foo) // => "bar"
957979
}
958980
// ...
959981
}
@@ -1170,7 +1192,7 @@ if (version === 2) {
11701192
new Vue({
11711193
customOption: 'foo',
11721194
created: function () {
1173-
console.log(this.$options.customOption) // -> 'foo'
1195+
console.log(this.$options.customOption) // => 'foo'
11741196
}
11751197
})
11761198
```
@@ -1435,7 +1457,7 @@ if (version === 2) {
14351457
console.log(msg)
14361458
})
14371459
vm.$emit('test', 'hi')
1438-
// -> "hi"
1460+
// => "hi"
14391461
```
14401462
14411463
<h3 id="vm-once">vm.$once( event, callback )</h3>

src/v2/guide/comparison.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Comparison with Other Frameworks
33
type: guide
4-
order: 29
4+
order: 701
55
---
66

77
This is definitely the most difficult page in the guide to write, but we do feel it's important. Odds are, you've had problems you tried to solve and you've used another library to solve them. You're here because you want to know if Vue can solve your specific problems better. That's what we hope to answer for you.

src/v2/guide/computed.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ var vm = new Vue({
6868
Here we have declared a computed property `reversedMessage`. The function we provided will be used as the getter function for the property `vm.reversedMessage`:
6969

7070
``` js
71-
console.log(vm.reversedMessage) // -> 'olleH'
71+
console.log(vm.reversedMessage) // => 'olleH'
7272
vm.message = 'Goodbye'
73-
console.log(vm.reversedMessage) // -> 'eybdooG'
73+
console.log(vm.reversedMessage) // => 'eybdooG'
7474
```
7575

7676
You can open the console and play with the example vm yourself. The value of `vm.reversedMessage` is always dependent on the value of `vm.message`.

src/v2/guide/custom-directive.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Custom Directives
33
type: guide
4-
order: 16
4+
order: 302
55
---
66

77
## Intro

src/v2/guide/deployment.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: Production Deployment Tips
2+
title: Production Deployment
33
type: guide
4-
order: 20
4+
order: 401
55
---
66

77
## Turn on Production Mode

src/v2/guide/events.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ var example2 = new Vue({
7575
})
7676

7777
// you can invoke methods in JavaScript too
78-
example2.greet() // -> 'Hello Vue.js!'
78+
example2.greet() // => 'Hello Vue.js!'
7979
```
8080

8181
Result:

src/v2/guide/filters.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: Filters
3+
type: guide
4+
order: 305
5+
---
6+
7+
Vue.js allows you to define filters that can be used to apply common text formatting. Filters are usable in two places: **mustache interpolations and `v-bind` expressions** (the latter supported in 2.1.0+). Filters should be appended to the end of the JavaScript expression, denoted by the "pipe" symbol:
8+
9+
``` html
10+
<!-- in mustaches -->
11+
{{ message | capitalize }}
12+
13+
<!-- in v-bind -->
14+
<div v-bind:id="rawId | formatId"></div>
15+
```
16+
17+
The filter function always receives the expression's value (the result of the former chain) as its first argument. In this example, the `capitalize` filter function will receive the value of `message` as its argument.
18+
19+
``` js
20+
new Vue({
21+
// ...
22+
filters: {
23+
capitalize: function (value) {
24+
if (!value) return ''
25+
value = value.toString()
26+
return value.charAt(0).toUpperCase() + value.slice(1)
27+
}
28+
}
29+
})
30+
```
31+
32+
Filters can be chained:
33+
34+
``` html
35+
{{ message | filterA | filterB }}
36+
```
37+
38+
In this case, `filterA`, defined with a single argument, will receive the value of `message`, and then the `filterB` function will be called with the result of `filterA` passed into `filterB`'s single argument.
39+
40+
Filters are JavaScript functions, therefore they can take arguments:
41+
42+
``` html
43+
{{ message | filterA('arg1', arg2) }}
44+
```
45+
46+
Here `filterA` is defined as a function taking three arguments. The value of `message` will be passed into the first argument. The plain string `'arg1'` will be passed into the `filterA` as its second argument, and the value of expression `arg2` will be evaluated and passed in as the third argument.

src/v2/guide/forms.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ vm.pick === vm.a
343343

344344
``` js
345345
// when selected:
346-
typeof vm.selected // -> 'object'
347-
vm.selected.number // -> 123
346+
typeof vm.selected // => 'object'
347+
vm.selected.number // => 123
348348
```
349349

350350
## Modifiers

src/v2/guide/installation.md

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Vue does **not** support IE8 and below, because it uses ECMAScript 5 features th
1717

1818
Detailed release notes for each version are available on [GitHub](https://github.com/vuejs/vue/releases).
1919

20+
## Vue Devtools
21+
22+
When using Vue, we recommend also installing the [Vue Devtools](https://github.com/vuejs/vue-devtools#vue-devtools) in your browser, allowing you to inspect and debug your Vue applications in a more user-friendly interface.
23+
2024
## Direct `<script>` Include
2125

2226
Simply download and include with a script tag. `Vue` will be registered as a global variable.

src/v2/guide/instance.md

+58-34
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ type: guide
44
order: 3
55
---
66

7-
## Constructor
7+
## Creating a Vue Instance
88

9-
Every Vue application is bootstrapped by creating a **root Vue instance** with the `Vue` constructor function:
9+
Every Vue application starts by creating a new **Vue instance** with the `Vue` function:
1010

1111
``` js
1212
var vm = new Vue({
@@ -16,46 +16,68 @@ var vm = new Vue({
1616

1717
Although not strictly associated with the [MVVM pattern](https://en.wikipedia.org/wiki/Model_View_ViewModel), Vue's design was partly inspired by it. As a convention, we often use the variable `vm` (short for ViewModel) to refer to our Vue instance.
1818

19-
When you instantiate a Vue instance, you need to pass in an **options object** which can contain options for data, template, element to mount on, methods, lifecycle callbacks, and more. The full list of options can be found in the [API reference](../api/#Options-Data).
19+
When you create a Vue instance, you pass in an **options object**. The majority of this guide describes how you can use these options to create your desired behavior. For reference, you can also browse the full list of options in the [API reference](../api/#Options-Data).
2020

21-
The `Vue` constructor can be extended to create reusable **component constructors** with pre-defined options:
21+
A Vue application consists of a **root Vue instance** created with `new Vue`, optionally organized into a tree of nested, reusable components. For example, a todo app's component tree might look like this:
2222

23-
``` js
24-
var MyComponent = Vue.extend({
25-
// extension options
26-
})
27-
28-
// all instances of `MyComponent` are created with
29-
// the pre-defined extension options
30-
var myComponentInstance = new MyComponent()
23+
```
24+
Root Instance
25+
|- TodoList
26+
|- TodoItem
27+
|- DeleteTodoButton
28+
|- EditTodoButton
29+
|- TodoListFooter
30+
|- ClearTodosButton
31+
|- TodoListStatistics
3132
```
3233

33-
Although it is possible to create extended instances imperatively, most of the time it is recommended to compose them declaratively in templates as custom elements. We will talk about [the component system](components.html) in detail later. For now, you just need to know that all Vue components are essentially extended Vue instances.
34+
We'll talk about [the component system](components.html) in detail later. For now, just know that all Vue components are also Vue instances, and so accept the same options object (except for a few root-specific options).
3435

35-
## Properties and Methods
36+
## Data and Methods
3637

37-
Each Vue instance **proxies** all the properties found in its `data` object:
38+
When a Vue instance is created, it adds all the properties found in its `data` object to Vue's **reactivity system**. When the values of those properties change, the view will "react", updating to match the new values.
3839

3940
``` js
41+
// Our data object
4042
var data = { a: 1 }
43+
44+
// The object is added to a Vue instance
4145
var vm = new Vue({
4246
data: data
4347
})
4448

45-
vm.a === data.a // -> true
49+
// These reference the same object!
50+
vm.a === data.a // => true
4651

47-
// setting the property also affects original data
52+
// Setting the property on the instance
53+
// also affects the original data
4854
vm.a = 2
49-
data.a // -> 2
55+
data.a // => 2
5056

5157
// ... and vice-versa
5258
data.a = 3
53-
vm.a // -> 3
59+
vm.a // => 3
60+
```
61+
62+
When this data changes, the view will re-render. It should be noted that properties in `data` are only **reactive** if they existed when the instance was created. That means if you add a new property, like:
63+
64+
``` js
65+
vm.b = 'hi'
5466
```
5567

56-
It should be noted that only these proxied properties are **reactive**, meaning any changes to their values will trigger the view to re-render. If you attach a new property to the instance after it has been created, it will not trigger any view updates. We will discuss the reactivity system in detail later.
68+
Then changes to `b` will not trigger any view updates. If you know you'll need a property later, but it starts out empty or non-existent, you'll just need to set some initial value. For example:
69+
70+
``` js
71+
data: {
72+
newTodoText: '',
73+
visitCount: 0,
74+
hideCompletedTodos: false,
75+
todos: [],
76+
error: null
77+
}
78+
```
5779

58-
In addition to data properties, Vue instances expose a number of useful instance properties and methods. These properties and methods are prefixed with `$` to differentiate them from proxied data properties. For example:
80+
In addition to data properties, Vue instances expose a number of useful instance properties and methods. These are prefixed with `$` to differentiate them from user-defined properties. For example:
5981

6082
``` js
6183
var data = { a: 1 }
@@ -64,25 +86,25 @@ var vm = new Vue({
6486
data: data
6587
})
6688

67-
vm.$data === data // -> true
68-
vm.$el === document.getElementById('example') // -> true
89+
vm.$data === data // => true
90+
vm.$el === document.getElementById('example') // => true
6991

7092
// $watch is an instance method
71-
vm.$watch('a', function (newVal, oldVal) {
72-
// this callback will be called when `vm.a` changes
93+
vm.$watch('a', function (newValue, oldValue) {
94+
// This callback will be called when `vm.a` changes
7395
})
7496
```
7597

76-
<p class="tip">Don't use [arrow functions](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions) on an instance property or callback (e.g. `vm.$watch('a', newVal => this.myMethod())`). As arrow functions are bound to the parent context, `this` will not be the Vue instance as you'd expect and `this.myMethod` will be undefined.</p>
77-
78-
Consult the [API reference](../api/#Instance-Properties) for the full list of instance properties and methods.
98+
In the future, you can consult the [API reference](../api/#Instance-Properties) for a full list of instance properties and methods.
7999

80100
## Instance Lifecycle Hooks
81101

82-
Each Vue instance goes through a series of initialization steps when it is created - for example, it needs to set up data observation, compile the template, mount the instance to the DOM, and update the DOM when data changes. Along the way, it will also invoke some **lifecycle hooks**, which give us the opportunity to execute custom logic. For example, the [`created`](../api/#created) hook is called after the instance is created:
102+
Each Vue instance goes through a series of initialization steps when it's created - for example, it needs to set up data observation, compile the template, mount the instance to the DOM, and update the DOM when data changes. Along the way, it also runs functions called **lifecycle hooks**, giving users the opportunity to add their own code at specific stages.
103+
104+
For example, the [`created`](../api/#created) hook can be used to run code after an instance is created:
83105

84106
``` js
85-
var vm = new Vue({
107+
new Vue({
86108
data: {
87109
a: 1
88110
},
@@ -91,13 +113,15 @@ var vm = new Vue({
91113
console.log('a is: ' + this.a)
92114
}
93115
})
94-
// -> "a is: 1"
116+
// => "a is: 1"
95117
```
96118

97-
There are also other hooks which will be called at different stages of the instance's lifecycle, for example [`mounted`](../api/#mounted), [`updated`](../api/#updated), and [`destroyed`](../api/#destroyed). All lifecycle hooks are called with their `this` context pointing to the Vue instance invoking it. You may have been wondering where the concept of "controllers" lives in the Vue world and the answer is: there are no controllers. Your custom logic for a component would be split among these lifecycle hooks.
119+
There are also other hooks which will be called at different stages of the instance's lifecycle, such as [`mounted`](../api/#mounted), [`updated`](../api/#updated), and [`destroyed`](../api/#destroyed). All lifecycle hooks are called with their `this` context pointing to the Vue instance invoking it.
120+
121+
<p class="tip">Don't use [arrow functions](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions) on an options property or callback, such as `created: () => console.log(this.a)` or `vm.$watch('a', newValue => this.myMethod())`. Since arrow functions are bound to the parent context, `this` will not be the Vue instance as you'd expect and `this.a` or `this.myMethod` will be undefined.</p>
98122

99123
## Lifecycle Diagram
100124

101-
Below is a diagram for the instance lifecycle. You don't need to fully understand everything going on right now, but this diagram will be helpful in the future.
125+
Below is a diagram for the instance lifecycle. You don't need to fully understand everything going on right now, but as you learn and build more, it will be a useful reference.
102126

103-
![Lifecycle](/images/lifecycle.png)
127+
![The Vue Instance Lifecycle](/images/lifecycle.png)

src/v2/guide/join.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Join the Vue.js Community!
33
type: guide
4-
order: 30
4+
order: 702
55
---
66

77
Vue's community is growing incredibly fast and if you're reading this, there's a good chance you're ready to join it. So... welcome!

0 commit comments

Comments
 (0)