Skip to content

Commit 0200afb

Browse files
authored
Merge pull request #241 from vuejs/master
获取官方文档更新
2 parents 01ea4b9 + 228fc12 commit 0200afb

File tree

17 files changed

+252
-171
lines changed

17 files changed

+252
-171
lines changed

src/api/index.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ type: api
7979

8080
> [Sentry](https://sentry.io), an error tracking service, provides [official integration](https://sentry.io/for/vue/) using this option.
8181
82+
### ignoredElements
83+
84+
- **Type:** `Array<string>`
85+
86+
- **Default:** `[]`
87+
88+
- **Usage:**
89+
90+
``` js
91+
Vue.config.ignoredElements = [
92+
'my-custom-web-component', 'another-web-component'
93+
]
94+
```
95+
96+
Make Vue ignore custom elements defined outside of Vue (e.g., using the Web Components APIs). Otherwise, it will throw a warning about an `Unknown custom element`, assuming that you forgot to register a global component or misspelled a component name.
97+
8298
### keyCodes
8399

84100
- **Type:** `{ [key: string]: number }`
@@ -249,7 +265,7 @@ type: api
249265

250266
- **Usage:**
251267

252-
Register or retrieve a global component.
268+
Register or retrieve a global component. Registration also automatically sets the component's `name` with the given `id`.
253269

254270
``` js
255271
// register an extended constructor
@@ -813,7 +829,7 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
813829

814830
- **Type:** `Array<string>`
815831

816-
- **default:** `["{{", "}}"]`
832+
- **default:** `{% raw %}["{{", "}}"]{% endraw %}`
817833

818834
- **Details:**
819835

@@ -1508,7 +1524,7 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
15081524

15091525
- **Does not expect expression**
15101526

1511-
- **Usage**
1527+
- **Usage:**
15121528

15131529
Skip compilation for this element and all its children. You can use this for displaying raw mustache tags. Skipping large numbers of nodes with no directives on them can also speed up compilation.
15141530

src/examples/index.md

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

77
> Dead simple Markdown editor.
88
9-
<iframe width="100%" height="500" src="https://jsfiddle.net/yyx990803/pq22eoj5/embedded/result,html,js,css" allowfullscreen="allowfullscreen" frameborder="0"></iframe>
9+
<iframe width="100%" height="500" src="https://jsfiddle.net/chrisvfritz/rdjjpc7a/embedded/result,html,js,css" allowfullscreen="allowfullscreen" frameborder="0"></iframe>

src/examples/todomvc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ order: 9
66

77
> This is a fully spec-compliant TodoMVC implementation in under 120 effective lines of JavaScript (excluding comments and blank lines).
88
9+
<p class="tip">Note that if your web browser is configured to block 3rd-party data/cookies, the example below will not work, as the `localStorage` data will fail to be saved from JSFiddle. You'll have to click on `Edit in JSFiddle` to see the live result.</p>
10+
911
<iframe width="100%" height="500" src="https://jsfiddle.net/yyx990803/4dr2fLb7/embedded/result,html,js,css" allowfullscreen="allowfullscreen" frameborder="0"></iframe>

src/guide/.npmignore

Whitespace-only changes.

src/guide/comparison.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,6 @@ Riot 2.0 provides a similar component-based development model (which is called a
324324

325325
- True conditional rendering. Riot renders all if branches and simply shows/hides them.
326326
- A far more powerful router. Riot’s routing API is extremely minimal.
327-
- More mature tooling support. Vue provides official support for [Webpack](https://github.com/vuejs/vue-loader), [Browserify](https://github.com/vuejs/vueify), and [SystemJS](https://github.com/vuejs/systemjs-plugin-vue), while Riot relies on community support for build system integration.
327+
- More mature tooling support. Vue provides official support for [Webpack](https://github.com/vuejs/vue-loader) and [Browserify](https://github.com/vuejs/vueify), while Riot relies on community support for build system integration.
328328
- [Transition effect system](transitions.html). Riot has none.
329329
- Better performance. [Despite advertising](https://github.com/vuejs/vuejs.org/issues/346) use of a virtual DOM, Riot in fact uses dirty checking and thus suffers from the same performance issues as Angular 1.

src/guide/components.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,17 @@ When a prop validation fails, Vue will produce a console warning (if using the d
419419

420420
## Custom Events
421421

422-
We have learned that the parent can pass data down to the child using props, but how do we communicate back to the parent when something happens? This is where custom events come in.
422+
We have learned that the parent can pass data down to the child using props, but how do we communicate back to the parent when something happens? This is where Vue's custom event system comes in.
423423

424424
### Using `v-on` with Custom Events
425425

426-
Every Vue instance implements the [Events interface](/api/#Instance-Methods-Events), which means it can:
426+
Every Vue instance implements an [events interface](/api/#Instance-Methods-Events), which means it can:
427427

428428
- Listen to an event using `$on(eventName)`
429429
- Trigger an event using `$emit(eventName)`
430430

431+
<p class="tip">Note that Vue's event system is separate from the browser's [EventTarget API](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget). Though they work similarly, `$on` and `$emit` are __not__ aliases for `addEventListener` and `dispatchEvent`.</p>
432+
431433
In addition, a parent component can listen to the events emitted from a child component using `v-on` directly in the template where the child component is used.
432434

433435
Here's an example:
@@ -981,12 +983,26 @@ Again, this _only_ works within string templates, as self-closing custom element
981983

982984
Components can recursively invoke themselves in their own template. However, they can only do so with the `name` option:
983985

986+
``` js
987+
name: 'unique-name-of-my-component'
988+
```
989+
990+
When you register a component globally using `Vue.component`, the global ID is automatically set as the component's `name` option.
991+
992+
``` js
993+
Vue.component('unique-name-of-my-component', {
994+
// ...
995+
})
996+
```
997+
998+
If you're not careful, recursive components can also lead to infinite loops:
999+
9841000
``` js
9851001
name: 'stack-overflow',
9861002
template: '<div><stack-overflow></stack-overflow></div>'
9871003
```
9881004

989-
A component like the above will result in a "max stack size exceeded" error, so make sure recursive invocation is conditional (i.e. uses a `v-if` that will eventually be false). When you register a component globally using `Vue.component`, the global ID is automatically set as the component's `name` option.
1005+
A component like the above will result in a "max stack size exceeded" error, so make sure recursive invocation is conditional (i.e. uses a `v-if` that will eventually be `false`).
9901006

9911007
### Inline Templates
9921008

src/guide/installation.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ vue_version: 2.0.3
66
dev_size: "188.88"
77
min_size: "62.54"
88
gz_size: "22.86"
9+
ro_gz_size: "16"
910
---
1011

1112
### Compatibility Note
@@ -49,9 +50,9 @@ There are two builds available, the standalone build and the runtime-only build.
4950

5051
- The standalone build includes the compiler and supports the `template` option. **It also relies on the presence of browser APIs so you cannot use it for server-side rendering.**
5152

52-
- The runtime-only build does not include the template compiler, and does not support the `template` option. You can only use the `render` option when using the runtime-only build, but it works with single-file components, because single-file components' templates are pre-compiled into `render` functions during the build step. The runtime-only build is roughly 30% lighter-weight than the standalone build, weighing only 16kb min+gzip.
53+
- The runtime-only build does not include the template compiler, and does not support the `template` option. You can only use the `render` option when using the runtime-only build, but it works with single-file components, because single-file components' templates are pre-compiled into `render` functions during the build step. The runtime-only build is roughly 30% lighter-weight than the standalone build, weighing only {{ro_gz_size}}kb min+gzip.
5354

54-
By default, the NPM package exports the **runtime-only** build. To use the standalone build, add the following alias to your webpack config:
55+
By default, the NPM package exports the **runtime-only** build. To use the standalone build, add the following alias to your Webpack config:
5556

5657
``` js
5758
resolve: {

src/guide/migration-vue-router.md

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ order: 26
88
99
## Router Initialization
1010

11-
### `router.start` <sup>deprecated</sup>
11+
### `router.start` <sup>replaced</sup>
1212

1313
There is no longer a special API to initialize an app with Vue Router. That means instead of:
1414

@@ -47,7 +47,7 @@ new Vue({
4747

4848
## Route Definitions
4949

50-
### `router.map` <sup>deprecated</sup>
50+
### `router.map` <sup>replaced</sup>
5151

5252
Routes are now defined as an array on a [`routes` option](http://router.vuejs.org/en/essentials/getting-started.html#javascript) at router instantiation. So these routes for example:
5353

@@ -82,7 +82,7 @@ The array syntax allows more predictable route matching, since iterating over an
8282
</div>
8383
{% endraw %}
8484

85-
### `router.on` <sup>deprecated</sup>
85+
### `router.on` <sup>removed</sup>
8686

8787
If you need to programmatically generate routes when starting up your app, you can do so by dynamically pushing definitions to a routes array. For example:
8888

@@ -128,7 +128,7 @@ router.match = createMatcher(
128128
</div>
129129
{% endraw %}
130130

131-
### `subRoutes` <sup>deprecated</sup>
131+
### `subRoutes` <sup>renamed</sup>
132132

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

@@ -139,7 +139,7 @@ router.match = createMatcher(
139139
</div>
140140
{% endraw %}
141141

142-
### `router.redirect` <sup>deprecated</sup>
142+
### `router.redirect` <sup>replaced</sup>
143143

144144
This is now an [option on route definitions](http://router.vuejs.org/en/essentials/redirect-and-alias.html). So for example, you will update:
145145

@@ -165,7 +165,7 @@ to a definition like below in your `routes` configuration:
165165
</div>
166166
{% endraw %}
167167

168-
### `router.alias` <sup>deprecated</sup>
168+
### `router.alias` <sup>replaced</sup>
169169

170170
This is now an [option on the definition for the route](http://router.vuejs.org/en/essentials/redirect-and-alias.html) you'd like to alias to. So for example, you will update:
171171

@@ -198,7 +198,7 @@ alias: ['/manage', '/administer', '/administrate']
198198
</div>
199199
{% endraw %}
200200

201-
### Arbitrary Route Properties
201+
### Arbitrary Route Properties <sup>replaced</sup>
202202

203203
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:
204204

@@ -240,20 +240,20 @@ if (route.meta.requiresAuth) {
240240

241241
Route matching now uses [path-to-regexp](https://github.com/pillarjs/path-to-regexp) under the hood, making it much more flexible than previously.
242242

243-
### One or More Named Parameters
243+
### One or More Named Parameters <sup>changed</sup>
244244

245245
The syntax has changed slightly, so `/category/*tags` for example, should be updated to `/category/:tags+`.
246246

247247
{% raw %}
248248
<div class="upgrade-path">
249249
<h4>Upgrade Path</h4>
250-
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of the deprecated route syntax.</p>
250+
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of the obsolete route syntax.</p>
251251
</div>
252252
{% endraw %}
253253

254254
## Links
255255

256-
### `v-link` <sup>deprecated</sup>
256+
### `v-link` <sup>replaced</sup>
257257

258258
The `v-link` directive has been replaced with a new [`<router-link>` component](http://router.vuejs.org/en/api/router-link.html), as this sort of job is now solely the responsibility of components in Vue 2. That means whenever wherever you have a link like this:
259259

@@ -267,16 +267,18 @@ You'll need to update it like this:
267267
<router-link to="/about">About</router-link>
268268
```
269269

270+
Note that `target="_blank"` is not supported on `<router-link>`, so if you need to open a link in a new tab, you have to use `<a>` instead.
271+
270272
{% raw %}
271273
<div class="upgrade-path">
272274
<h4>Upgrade Path</h4>
273275
<p>Run the <a href="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of the <code>v-link</code> directive.</p>
274276
</div>
275277
{% endraw %}
276278

277-
### `v-link-active` <sup>deprecated</sup>
279+
### `v-link-active` <sup>replaced</sup>
278280

279-
The `v-link-active` directive has also been deprecated in favor of specifying a separate tag on [the `<router-link>` component](http://router.vuejs.org/en/api/router-link.html). So for example, you'll update this:
281+
The `v-link-active` directive has also been replaced by the `tag` attribute on [the `<router-link>` component](http://router.vuejs.org/en/api/router-link.html). So for example, you'll update this:
280282

281283
``` html
282284
<li v-link-active>
@@ -303,7 +305,7 @@ The `<a>` will be the actual link (and will get the correct href), but the activ
303305

304306
## Programmatic Navigation
305307

306-
### `router.go`
308+
### `router.go` <sup>changed</sup>
307309

308310
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.
309311

@@ -316,7 +318,7 @@ For consistency with the [HTML5 History API](https://developer.mozilla.org/en-US
316318

317319
## Router Options: Modes
318320

319-
### `hashbang: false` <sup>deprecated</sup>
321+
### `hashbang: false` <sup>removed</sup>
320322

321323
Hashbangs are no longer required for Google to crawl a URL, so they are no longer the default (or even an option) for the hash strategy.
322324

@@ -327,7 +329,7 @@ Hashbangs are no longer required for Google to crawl a URL, so they are no longe
327329
</div>
328330
{% endraw %}
329331

330-
### `history: true` <sup>deprecated</sup>
332+
### `history: true` <sup>replaced</sup>
331333

332334
All routing mode options have been condensed into a single [`mode` option](http://router.vuejs.org/en/api/options.html#mode). Update:
333335

@@ -352,7 +354,7 @@ var router = new VueRouter({
352354
</div>
353355
{% endraw %}
354356

355-
### `abstract: true` <sup>deprecated</sup>
357+
### `abstract: true` <sup>replaced</sup>
356358

357359
All routing mode options have been condensed into a single [`mode` option](http://router.vuejs.org/en/api/options.html#mode). Update:
358360

@@ -379,7 +381,7 @@ var router = new VueRouter({
379381

380382
## Route Options: Misc
381383

382-
### `saveScrollPosition` <sup>deprecated</sup>
384+
### `saveScrollPosition` <sup>replaced</sup>
383385

384386
This has been replaced with a [`scrollBehavior` option](http://router.vuejs.org/en/advanced/scroll-behavior.html) that accepts a function, so that the scroll behavior is completely customizable - even per route. This opens many new possibilities, but to simply replicate the old behavior of:
385387

@@ -402,7 +404,7 @@ scrollBehavior: function (to, from, savedPosition) {
402404
</div>
403405
{% endraw %}
404406

405-
### `root` <sup>deprecated</sup>
407+
### `root` <sup>renamed</sup>
406408

407409
Renamed to `base` for consistency with [the HTML `<base>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base).
408410

@@ -413,7 +415,7 @@ Renamed to `base` for consistency with [the HTML `<base>` element](https://devel
413415
</div>
414416
{% endraw %}
415417

416-
### `transitionOnLoad` <sup>deprecated</sup>
418+
### `transitionOnLoad` <sup>removed</sup>
417419

418420
This option is no longer necessary now that Vue's transition system has explicit [`appear` transition control](transitions.html#Transitions-on-Initial-Render).
419421

@@ -424,7 +426,7 @@ This option is no longer necessary now that Vue's transition system has explicit
424426
</div>
425427
{% endraw %}
426428

427-
### `suppressTransitionError` <sup>deprecated</sup>
429+
### `suppressTransitionError` <sup>removed</sup>
428430

429431
Removed due to hooks simplification. If you really must suppress transition errors, you can use [`try`...`catch`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch) instead.
430432

@@ -437,7 +439,7 @@ Removed due to hooks simplification. If you really must suppress transition erro
437439

438440
## Route Hooks
439441

440-
### `activate` <sup>deprecated</sup>
442+
### `activate` <sup>replaced</sup>
441443

442444
Use [`beforeRouteEnter`](http://router.vuejs.org/en/advanced/navigation-guards.html#incomponent-guards) in the component instead.
443445

@@ -448,7 +450,7 @@ Use [`beforeRouteEnter`](http://router.vuejs.org/en/advanced/navigation-guards.h
448450
</div>
449451
{% endraw %}
450452

451-
### `canActivate` <sup>deprecated</sup>
453+
### `canActivate` <sup>replaced</sup>
452454

453455
Use [`beforeEnter`](http://router.vuejs.org/en/advanced/navigation-guards.html#perroute-guard) in the route instead.
454456

@@ -459,7 +461,7 @@ Use [`beforeEnter`](http://router.vuejs.org/en/advanced/navigation-guards.html#p
459461
</div>
460462
{% endraw %}
461463

462-
### `deactivate` <sup>deprecated</sup>
464+
### `deactivate` <sup>removed</sup>
463465

464466
Use the component's [`beforeDestroy`](/api/#beforeDestroy) or [`destroyed`](/api/#destroyed) hooks instead.
465467

@@ -470,7 +472,7 @@ Use the component's [`beforeDestroy`](/api/#beforeDestroy) or [`destroyed`](/api
470472
</div>
471473
{% endraw %}
472474

473-
### `canDeactivate` <sup>deprecated</sup>
475+
### `canDeactivate` <sup>replaced</sup>
474476

475477
Use [`beforeRouteLeave`](http://router.vuejs.org/en/advanced/navigation-guards.html#incomponent-guards) in the component instead.
476478

@@ -481,7 +483,7 @@ Use [`beforeRouteLeave`](http://router.vuejs.org/en/advanced/navigation-guards.h
481483
</div>
482484
{% endraw %}
483485

484-
### `canReuse: false` <sup>deprecated</sup>
486+
### `canReuse: false` <sup>removed</sup>
485487

486488
There's no longer a use case for this in the new Vue Router.
487489

@@ -492,9 +494,9 @@ There's no longer a use case for this in the new Vue Router.
492494
</div>
493495
{% endraw %}
494496

495-
### `data` <sup>deprecated</sup>
497+
### `data` <sup>replaced</sup>
496498

497-
The `$route` property is reactive, so you can just use a watcher to react to route changes, like this:
499+
The `$route` property is now reactive, so you can just use a watcher to react to route changes, like this:
498500

499501
``` js
500502
watch: {
@@ -514,7 +516,7 @@ methods: {
514516
</div>
515517
{% endraw %}
516518

517-
### `$loadingRouteData` <sup>deprecated</sup>
519+
### `$loadingRouteData` <sup>removed</sup>
518520

519521
Define your own property (e.g. `isLoading`), then update the loading state in a watcher on the route. For example, if fetching data with [axios](https://github.com/mzabriskie/axios):
520522

0 commit comments

Comments
 (0)