Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1689be6

Browse files
clarify extend vs. component, + v-view & routing
1 parent 0c40bdb commit 1689be6

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

‎source/api/directives.md‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,6 @@ When the argument is prefixed with `$`, Vue.js will automatically apply prefixed
8585

8686
<p class="tip">It is recommended to use `v-style` instead of mustache bindings inside `style` attribute because Internet Explorer, regardless of version, will remove invalid inline styles when parsing the HTML.</p>
8787

88-
### v-repeat
89-
90-
- This directive requires the value to be Array or falsy.
91-
- This directive can trigger transitions.
92-
93-
Create a child ViewModel for every item in the binding Array. These child ViewModels will be automatically created / destroyed when mutating methods, e.g. `push()`, are called on the Array. For more details see [Displaying a List](/guide/list.html).
94-
9588
### v-on
9689

9790
- This directive requires exactly one argument.
@@ -111,8 +104,17 @@ Create a two-way binding on a form or editable element. Data is synced on every
111104

112105
Conditionally insert / remove the element based on the truthy-ness of the binding value.
113106

107+
### v-repeat
108+
109+
- This directive requires the value to be Array or falsy.
110+
- This directive creates child ViewModels.
111+
- This directive can trigger transitions.
112+
113+
Create a child ViewModel for every item in the binding Array. These child ViewModels will be automatically created / destroyed when mutating methods, e.g. `push()`, are called on the Array. For more details see [Displaying a List](/guide/list.html).
114+
114115
### v-with
115116

117+
- This directive creates child ViewModels.
116118
- This directive accepts only keypaths, no expressions.
117119

118120
Compile this element as a child ViewModel, inheriting data from the parent. You can either pass in an Object which will be used as the `data` option, or bind individual parent properties to the child with different keys. This directive can be used in combination with `v-component`.
@@ -145,6 +147,13 @@ Example inehriting individual properties (using the same data):
145147
</div>
146148
```
147149

150+
### v-view
151+
152+
- This directive creates child ViewModels.
153+
- This directive can trigger transitions.
154+
155+
Conditionally instantiate ViewModels, using the bound value as the Component ID to look up constructors with. When the bound value changes, existing ViewModel will be destroyed and a new ViewModel will be created. When a ViewModel is created, the original element will be replaced, but all attributes will be copied to the new element. For more details, see [Routing](/guide/application.html#routing).
156+
148157
## Literal Directives
149158

150159
> Literal directives treat their attribute value as a plain string; they do not attempt to bind themselves to anything. All they do is executing the `bind()` function with the string value once. Literal directives accept mustache expressions inside their value, but these expressions will be evaludated only once on first compile and do not react to data changes.

‎source/guide/application.md‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,31 @@ Similar modularization can be achieved in Browserify too, with transform plugins
2323

2424
## Routing
2525

26-
You can implement some rudimentary routing logic by manually updating a state object on hashchange. An example can be found [here](https://github.com/yyx990803/vue/blob/master/test/functional/fixtures/routing.html).
26+
You can implement some rudimentary routing logic by manually listening on hashchange and utilizing the `v-view` direcitve. The `v-view` directive is essentially a dynamic component loader: it binds to a string value and creates a new VM instance using that string as the Component ID (and destroys the old VM if it exists). Example:
2727

28-
It is also possible to implement something more robust with the help of routing components such as [Page.js](https://github.com/visionmedia/page.js) or [Director](https://github.com/flatiron/director). There is plan to provide a vue-router component that integrates with Vue.js for easier routing and deep linking.
28+
``` html
29+
<div id="app">
30+
<div v-view="currentView"></div>
31+
</div>
32+
```
33+
34+
``` js
35+
Vue.component('home', { /* ... */ })
36+
Vue.component('page1', { /* ... */ })
37+
38+
var app = new Vue({
39+
el: '#app',
40+
data: {
41+
currentView: 'home'
42+
}
43+
})
44+
```
45+
46+
The `home` component will be rendered in place of `v-view`. When `currentView`'s value changes to `page1`, the existing `home` component will be destroyed and replaced by the new `page1` component. The full, more detailed example can be found [here](https://github.com/yyx990803/vue/blob/master/test/functional/fixtures/routing.html).
47+
48+
<p class="tip">`v-view` will replace the element it's bound to with the new instantiated VM's element, so avoid using it on your root element.</p>
49+
50+
With `v-view` it's very easy to leverage standalone routing libraries such as [Page.js](https://github.com/visionmedia/page.js) and [Director](https://github.com/flatiron/director). There is plan to provide a vue-router component that integrates with Vue.js for easier routing and deep linking.
2951

3052
## Communication with Server
3153

‎source/guide/composition.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ If you prefer, components can also be used in the form of a custom element tag:
3636

3737
<p class="tip">To avoid naming collisions with native elements and stay consistent with the W3C Custom Elements specification, the component's ID **must** contain a hyphen `-` to be usable as a custom tag.</p>
3838

39+
It is important to understand the difference between `Vue.extend()` and `Vue.component()`. Since `Vue` itself is a constructor, `Vue.extend()` is a **class inheritance method**. Its task is to create a sub-class of `Vue` and return the constructor. `Vue.component()`, on the other hand, is an **asset registration method** similar to `Vue.directive()` and `Vue.filter()`. Its task is to associate a given constructor with a string ID so Vue.js can pick it up in templates. When directly passing in options to `Vue.component()`, it calls `Vue.extend()` under the hood.
40+
41+
Vue.js supports two different API paradigms: the class-based, imperative, Backbone style API, and the markup-based, declarative, Web Components style API. If you are confused, think about how you can create an image element with `new Image()`, or with an `<img>` tag. Both are useful in its own right and Vue.js tries to provide both for maximum flexibility.
42+
3943
## Partials and {&#123;>yield&#125;}
4044

4145
You can use partials in templates with {&#123;>partial-id&#125;}, which inserts the partial registered via `Vue.partial('partial-id', '...')`. But there is a special reserved partial ID: `yield`. Basically, the `yield` partial inside a template serves as a insertion point for the original, pre-compile content inside the element. This syntax allows components to be easily nested and composed while maintaining their custom markup. For example:
@@ -80,10 +84,10 @@ var MyComponent = Vue.extend({
8084
components: {
8185
// ...
8286
},
83-
transitions: {
87+
partials: {
8488
// ...
8589
},
86-
partials: {
90+
effects: {
8791
// ...
8892
}
8993
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /