Skip to content

Commit 464eea7

Browse files
authored
Merge pull request #298 from vuejs/master
获取官方更新
2 parents 091d58a + 5b35d46 commit 464eea7

24 files changed

+1014
-683
lines changed

src/images/components.png

-9.41 KB
Loading

src/images/data.png

-38.4 KB
Loading

src/images/hn-architecture.png

-107 KB
Loading

src/images/hn.png

-116 KB
Loading

src/images/lifecycle.png

-81.6 KB
Loading

src/images/mvvm.png

-26.8 KB
Loading

src/images/props-events.png

-16.8 KB
Loading

src/images/state.png

-22.2 KB
Loading

src/images/typescript-type-error.png

23.9 KB
Loading
-158 KB
Loading

src/images/vue-component.png

-125 KB
Loading

src/v2/guide/comparison.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Comparison with Other Frameworks
33
type: guide
4-
order: 28
4+
order: 29
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/installation.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
title: Installation
33
type: guide
44
order: 1
5-
vue_version: 2.1.3
6-
dev_size: "206.14"
7-
min_size: "67.60"
8-
gz_size: "24.72"
9-
ro_gz_size: "17.14"
5+
vue_version: 2.1.6
6+
dev_size: "212.24"
7+
min_size: "69.33"
8+
gz_size: "25.39"
9+
ro_gz_size: "17.67"
1010
---
1111

1212
### Compatibility Note

src/v2/guide/join.md

Lines changed: 1 addition & 1 deletion
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: 29
4+
order: 30
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!

src/v2/guide/migration-vue-router.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Migration from Vue Router 0.7.x
33
type: guide
4-
order: 26
4+
order: 27
55
---
66

77
> Only Vue Router 2 is compatible with Vue 2, so if you're updating Vue, you'll have to update Vue Router as well. That's why we've included details on the migration path here in the main docs. For a complete guide on using the new Vue Router, see the [Vue Router docs](http://router.vuejs.org/en/).

src/v2/guide/migration-vuex.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Migration from Vuex 0.6.x to 1.0
33
type: guide
4-
order: 27
4+
order: 28
55
---
66

77
> Vuex 2.0 is released, but this guide only covers the migration to 1.0? Is that a typo? Also, it looks like Vuex 1.0 and 2.0 were released simultaneously. What's going on? Which one should I use and what's compatible with Vue 2.0?

src/v2/guide/migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Migration from Vue 1.x
33
type: guide
4-
order: 25
4+
order: 26
55
---
66

77
## FAQ

src/v2/guide/render-function.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ One thing to note: similar to how `v-bind:class` and `v-bind:style` have special
177177
// Scoped slots in the form of
178178
// { name: props => VNode | Array<VNode> }
179179
scopedSlots: {
180-
default: props => h('span', props.text)
180+
default: props => createElement('span', props.text)
181181
},
182182
// The name of a slot if the child of a component
183183
slot: 'name-of-slot'

src/v2/guide/state-management.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var store = {
4949
}
5050
```
5151

52-
Notice all actions that mutate the store's state are put inside the store itself. This type of centralized state management makes it easier to understand what type of mutations could happen and how are they triggered. When something goes wrong, we'll also now have a log of what happened leading up to the bug.
52+
Notice all actions that mutate the store's state are put inside the store itself. This type of centralized state management makes it easier to understand what type of mutations could happen and how are they triggered. Now when something goes wrong, we'll also have a log of what happened leading up to the bug.
5353

5454
In addition, each instance/component can still own and manage its own private state:
5555

src/v2/guide/typescript.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
title: TypeScript Support
3+
type: guide
4+
order: 25
5+
---
6+
7+
## Official Declaration Files
8+
9+
A static type system can help prevent many potential runtime errors, especially as applications grow. That's why Vue ships with [official type declarations](https://github.com/vuejs/vue/tree/dev/types) for [TypeScript](https://www.typescriptlang.org/) - not only in Vue core, but also [for Vue Router](https://github.com/vuejs/vue-router/tree/dev/types) and [for Vuex](https://github.com/vuejs/vuex/tree/dev/types) as well.
10+
11+
Since these are [published on NPM](https://unpkg.com/vue/types/), you don't even need external tools like `Typings`, as declarations are automatically imported with Vue. That means all you need is a simple:
12+
13+
``` ts
14+
import Vue = require('vue')
15+
```
16+
17+
Then all methods, properties, and parameters will be type checked. For example, if you misspell the `template` component option as `tempate` (missing the `l`), the TypeScript compiler will print an error message at compile time. If you're using an editor that can lint TypeScript, such as [Visual Studio Code](https://code.visualstudio.com/), you'll even be able to catch these errors before compilation:
18+
19+
![TypeScript Type Error in Visual Studio Code](/images/typescript-type-error.png)
20+
21+
### Compilation Options
22+
23+
Vue's declaration files require the `--lib DOM,ES2015.Promise` [compiler option](https://www.typescriptlang.org/docs/handbook/compiler-options.html). You can pass this option to the `tsc` command or add the equivalent to a `tsconfig.json` file.
24+
25+
### Accessing Vue's Type Declarations
26+
27+
If you want to annotate your own code with Vue's types, you can access them on Vue's exported object. For example, to annotate an exported component options object (e.g. in a `.vue` file):
28+
29+
``` ts
30+
import Vue = require('vue')
31+
32+
export default {
33+
props: ['message'],
34+
template: '<span>{{ message }}</span>'
35+
} as Vue.ComponentOptions<Vue>
36+
```
37+
38+
## Class-Style Vue Components
39+
40+
Vue component options can easily be annotated with types:
41+
42+
``` ts
43+
import Vue = require('vue')
44+
45+
// Declare the component's type
46+
interface MyComponent extends Vue {
47+
message: string
48+
onClick (): void
49+
}
50+
51+
export default {
52+
template: '<button @click="onClick">Click!</button>',
53+
data: function () {
54+
return {
55+
message: 'Hello!'
56+
}
57+
},
58+
methods: {
59+
onClick: function () {
60+
// TypeScript knows that `this` is of type MyComponent
61+
// and that `this.message` will be a string
62+
window.alert(this.message)
63+
}
64+
}
65+
// We need to explicitly annotate the exported options object
66+
// with the MyComponent type
67+
} as Vue.ComponentOptions<MyComponent>
68+
```
69+
70+
Unfortunately, there are a few limitations here:
71+
72+
- __TypeScript can't infer all types from Vue's API.__ For example, it doesn't know that the `message` property returned in our `data` function will be added to the `MyComponent` instance. That means if we assigned a number or boolean value to `message`, linters and compilers wouldn't be able to raise an error, complaining that it should be a string.
73+
74+
- Because of the previous limitation, __annotating types like this can be verbose__. The only reason we have to manually declare `message` as a string is because TypeScript can't infer the type in this case.
75+
76+
Fortunately, [vue-class-component](https://github.com/vuejs/vue-class-component) can solve both of these problems. It's an official companion library that allows you to declare components as native JavaScript classes, with a `@Component` decorator. As an example, let's rewrite the above component:
77+
78+
``` ts
79+
import Vue = require('vue')
80+
import Component from 'vue-class-component'
81+
82+
// The @Component decorator indicates the class is a Vue component
83+
@Component({
84+
// All component options are allowed in here
85+
template: '<button @click="onClick">Click!</button>'
86+
})
87+
export default class MyComponent extends Vue {
88+
// Initial data can be declared as instance properties
89+
message: string = 'Hello!'
90+
91+
// Component methods can be declared as instance methods
92+
onClick (): void {
93+
window.alert(this.message)
94+
}
95+
}
96+
```
97+
98+
With this syntax alternative, our component definition is not only shorter, but TypeScript can also infer the types of `message` and `onClick` without explicit interface declarations. This strategy even allows you to handle types for computed properties, lifecycle hooks, and render functions. For full usage details, see [the vue-class-component docs](https://github.com/vuejs/vue-class-component#vue-class-component).

themes/vue/_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
site_description: "Vue.js - Intuitive, Fast and Composable MVVM for building interactive interfaces."
22
google_analytics: UA-46852172-1
33
root_domain: vuejs.org
4-
vue_version: 2.1.3
4+
vue_version: 2.1.6

themes/vue/layout/partials/language_dropdown.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
<li><a href="https://cn.vuejs.org/" class="nav-link" target="_blank">中文</a></li>
55
<li><a href="https://jp.vuejs.org/" class="nav-link" target="_blank">日本語</a></li>
66
<li><a href="https://ru.vuejs.org/" class="nav-link" target="_blank">Русский</a></li>
7+
<li><a href="https://kr.vuejs.org/" class="nav-link" target="_blank">한국어</a></li>
78
</ul>
89
</li>

0 commit comments

Comments
 (0)