Skip to content

Commit 379c7b9

Browse files
authored
Merge pull request #188 from vuejs/master
获取vuejs.org官方文档更新
2 parents 67f547e + 9b2607d commit 379c7b9

35 files changed

+436
-138
lines changed

src/api/index.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ type: api
7777

7878
Assign a handler for uncaught errors during component render and watchers. The handler gets called with the error and the Vue instance.
7979

80+
> [Sentry](https://sentry.io), an error tracking service, provides [official integration](https://sentry.io/for/vue/) using this option.
81+
8082
### keyCodes
8183

8284
- **Type:** `{ [key: string]: number }`
@@ -86,10 +88,14 @@ type: api
8688
- **Usage:**
8789

8890
``` js
89-
Vue.config.keyCodes = { esc: 27 }
91+
Vue.config.keyCodes = {
92+
v: 86,
93+
f1: 112,
94+
mediaPlayPause: 179
95+
}
9096
```
9197

92-
Define custom key aliases for v-on.
98+
Define custom key alias(es) for v-on.
9399

94100
## Global API
95101

@@ -1170,7 +1176,7 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
11701176

11711177
// or, render off-document and append afterwards:
11721178
var component = new MyComponent().$mount()
1173-
document.getElementById('app').appendChild(vm.$el)
1179+
document.getElementById('app').appendChild(component.$el)
11741180
```
11751181

11761182
- **See also:**

src/examples/firebase.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ order: 2
66

77
> This example uses [Firebase](https://firebase.google.com/) as the data persistence backend and syncs between clients in real time (you can try opening it in multiple browser tabs). In addition, it performs instant validation using computed properties and triggers CSS transitions when adding/removing items.
88
9-
<iframe width="100%" height="500" src="https://jsfiddle.net/yyx990803/hkrxmp0h/embedded/result,html,js,css" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
9+
<iframe width="100%" height="500" src="https://jsfiddle.net/chrisvfritz/pyLbpzzx/embedded/result,html,js,css" allowfullscreen="allowfullscreen" frameborder="0"></iframe>

src/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: 26
4+
order: 28
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/guide/components.md

-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@ new Vue({
213213
</script>
214214
{% endraw %}
215215

216-
The `el` option also requires a function value when used in a component instance, for exactly the same reason.
217-
218216
### Composing Components
219217

220218
Components are meant to be used together, most commonly in parent-child relationships: component A may use component B in its own template. They inevitably need to communicate to one another: the parent may need to pass data down to the child, and the child may need to inform the parent of something that happened in the child. However, it is also very important to keep the parent and the child as decoupled as possible via a clearly-defined interface. This ensures each component's code can be written and reasoned about in relative isolation, thus making them more maintainable and potentially easier to reuse.

src/guide/deployment.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: Deploying For Production
3+
type: guide
4+
order: 20
5+
---
6+
7+
## Stripping Out Warnings
8+
9+
The minified standalone build of Vue has already stripped out all the warnings for you for a smaller file size, but when you are using tools like Webpack or Browserify, you will need some additional configuration to achieve this.
10+
11+
### Webpack
12+
13+
Use Webpack's [DefinePlugin](http://webpack.github.io/docs/list-of-plugins.html#defineplugin) to indicate a production environment, so that warning blocks can be automatically dropped by UglifyJS during minification. Example config:
14+
15+
``` js
16+
var webpack = require('webpack')
17+
18+
module.exports = {
19+
// ...
20+
plugins: [
21+
// ...
22+
new webpack.DefinePlugin({
23+
'process.env': {
24+
NODE_ENV: '"production"'
25+
}
26+
}),
27+
new webpack.optimize.UglifyJsPlugin({
28+
compress: {
29+
warnings: false
30+
}
31+
})
32+
]
33+
}
34+
```
35+
36+
### Browserify
37+
38+
- Run your bundling command with `NODE_ENV` set to `"production"`. This tells `vueify` to avoid including hot-reload and development related code.
39+
- Apply a global [envify](https://github.com/hughsk/envify) transform to your bundle. This allows the minifier to strip out all the warnings in Vue's source code wrapped in env variable conditional blocks. For example:
40+
41+
42+
``` bash
43+
NODE_ENV=production browserify -g envify -e main.js | uglifyjs -c -m > build.js
44+
```
45+
46+
- To extract styles to a separate css file use a extract-css plugin which is included in vueify.
47+
48+
``` bash
49+
NODE_ENV=production browserify -g envify -p [ vueify/plugins/extract-css -o build.css ] -e main.js | uglifyjs -c -m > build.js
50+
```
51+
52+
## Tracking Runtime Errors
53+
54+
If a runtime error occurs during a component's render, it will be passed to the global `Vue.config.errorHandler` config function if it has been set. It might be a good idea to leverage this hook together with an error-tracking service like [Sentry](https://sentry.io), which provides [an official integration](https://sentry.io/for/vue/) for Vue.
55+
56+
## Extracting CSS
57+
58+
When using [Single-File Components](./single-file-components.html), the `<style>` tags are injected dynamically at runtime during development. In production you may want to extract the styles across all components into a single CSS file. For details on how to achieve this, consult the respective documentation for [vue-loader](http://vue-loader.vuejs.org/en/configurations/extract-css.html) and [vueify](https://github.com/vuejs/vueify#css-extraction).
59+
60+
The official `webpack` template from `vue-cli` has this already configured out of the box.

src/guide/events.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ To address this problem, Vue provides **event modifiers** for `v-on`. Recall tha
173173
<form v-on:submit.prevent="onSubmit"></form>
174174

175175
<!-- modifiers can be chained -->
176-
<a v-on:click.stop.prevent="doThat">
176+
<a v-on:click.stop.prevent="doThat"></a>
177177

178178
<!-- just the modifier -->
179179
<form v-on:submit.prevent></form>
@@ -217,13 +217,7 @@ Here's the full list of key modifier aliases:
217217
- left
218218
- right
219219

220-
Single letter key aliases are also supported.
221-
222-
``` html
223-
<input v-on:keyup.v="say('That is the first letter in Vue')">
224-
```
225-
226-
If necessary, you can even define custom key modifier aliases:
220+
You can also [define custom key modifier aliases](/api/#keyCodes) via the global `config.keyCodes` object:
227221

228222
``` js
229223
// enable v-on:keyup.f1

src/guide/forms.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ new Vue({
3636

3737
``` html
3838
<span>Multiline message is:</span>
39-
<p>{{ message }}</p>
39+
<p style="white-space: pre">{{ message }}</p>
4040
<br>
4141
<textarea v-model="message" placeholder="add multiple lines"></textarea>
4242
```

src/guide/installation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ By default, the NPM package exports the **runtime-only** build. To use the stand
5656
``` js
5757
resolve: {
5858
alias: {
59-
vue: 'vue/dist/vue.js'
59+
'vue$': 'vue/dist/vue.js'
6060
}
6161
}
6262
```

src/guide/instance.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ 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>
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>
7777

7878
Consult the [API reference](/api) for the full list of instance properties and methods.
7979

src/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: 27
4+
order: 29
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/guide/migration-vue-router.md

+88-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,49 @@
11
---
22
title: Migration from Vue Router 0.7.x
33
type: guide
4-
order: 25
4+
order: 26
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/).
88
9-
<p class="tip">The list of deprecations below should be relatively complete, but the migration helper is still being updated to catch them.</p>
9+
## Router Initialization
10+
11+
### `router.start` <sup>deprecated</sup>
12+
13+
There is no longer a special API to initialize an app with Vue Router. That means instead of:
14+
15+
``` js
16+
router.start({
17+
template: '<router-view></router-view>'
18+
}, '#app')
19+
```
20+
21+
You'll just pass a router property to a Vue instance:
22+
23+
``` js
24+
new Vue({
25+
el: '#app',
26+
router: router,
27+
template: '<router-view></router-view>'
28+
})
29+
```
30+
31+
Or, if you're using the runtime-only build of Vue:
32+
33+
``` js
34+
new Vue({
35+
el: '#app',
36+
router: router,
37+
render: h => h('router-view')
38+
})
39+
```
40+
41+
{% raw %}
42+
<div class="upgrade-path">
43+
<h4>Upgrade Path</h4>
44+
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of <code>router.start</code> being called.</p>
45+
</div>
46+
{% endraw %}
1047

1148
## Route Definitions
1249

@@ -91,14 +128,14 @@ router.match = createMatcher(
91128
</div>
92129
{% endraw %}
93130

94-
### `subroutes` <sup>deprecated</sup>
131+
### `subRoutes` <sup>deprecated</sup>
95132

96133
[Renamed to `children`](http://router.vuejs.org/en/essentials/nested-routes.html) for consistency within Vue and with other routing libraries.
97134

98135
{% raw %}
99136
<div class="upgrade-path">
100137
<h4>Upgrade Path</h4>
101-
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of the <code>subroutes</code> option.</p>
138+
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of the <code>subRoutes</code> option.</p>
102139
</div>
103140
{% endraw %}
104141

@@ -161,6 +198,44 @@ alias: ['/manage', '/administer', '/administrate']
161198
</div>
162199
{% endraw %}
163200

201+
### Arbitrary Route Properties
202+
203+
Arbitrary route properties must now be scoped under the new meta property, to avoid conflicts with future features. So for example, if you had defined:
204+
205+
``` js
206+
'/admin': {
207+
component: AdminPanel,
208+
requiresAuth: true
209+
}
210+
```
211+
212+
Then you would now update it to:
213+
214+
``` js
215+
{
216+
path: '/admin',
217+
component: AdminPanel,
218+
meta: {
219+
requiresAuth: true
220+
}
221+
}
222+
```
223+
224+
Then when later accessing this property on a route, you will still go through meta. For example:
225+
226+
``` js
227+
if (route.meta.requiresAuth) {
228+
// ...
229+
}
230+
```
231+
232+
{% raw %}
233+
<div class="upgrade-path">
234+
<h4>Upgrade Path</h4>
235+
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of arbitrary route properties not scoped under meta.</p>
236+
</div>
237+
{% endraw %}
238+
164239
## Route Matching
165240

166241
Route matching now uses [path-to-regexp](https://github.com/pillarjs/path-to-regexp) under the hood, making it much more flexible than previously.
@@ -230,12 +305,12 @@ The `<a>` will be the actual link (and will get the correct href), but the activ
230305

231306
### `router.go`
232307

233-
[Renamed to `router.push`](http://router.vuejs.org/en/essentials/navigation.html#routerpushlocation) for consistency with terminology used in the [HTML5 History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API).
308+
For consistency with the [HTML5 History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API), `router.go` is now only used for [back/forward navigation](https://router.vuejs.org/en/essentials/navigation.html#routergon), while [`router.push`](http://router.vuejs.org/en/essentials/navigation.html#routerpushlocation) is used to navigate to a specific page.
234309

235310
{% raw %}
236311
<div class="upgrade-path">
237312
<h4>Upgrade Path</h4>
238-
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of <code>router.go</code> being called.</p>
313+
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of <code>router.go</code> being used where <code>router.push</code> should be used instead.</p>
239314
</div>
240315
{% endraw %}
241316

@@ -453,20 +528,22 @@ data: function () {
453528
},
454529
watch: {
455530
'$route': function () {
456-
this.isLoading = true
457-
this.fetchData().then(() => {
458-
this.isLoading = false
531+
var self = this
532+
self.isLoading = true
533+
self.fetchData().then(function () {
534+
self.isLoading = false
459535
})
460536
}
461537
},
462538
methods: {
463539
fetchData: function () {
540+
var self = this
464541
return axios.get('/api/posts')
465542
.then(function (response) {
466-
this.posts = response.data.posts
543+
self.posts = response.data.posts
467544
})
468545
.catch(function (error) {
469-
this.fetchError = error
546+
self.fetchError = error
470547
})
471548
}
472549
}

0 commit comments

Comments
 (0)