Skip to content

Commit 24477f3

Browse files
authored
Merge pull request #22 from vuejs/2.0
2.0
2 parents 14c2686 + 0569402 commit 24477f3

File tree

6 files changed

+338
-15
lines changed

6 files changed

+338
-15
lines changed

src/api/index.md

Lines changed: 322 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,6 @@ type: api
378378

379379
### propsData
380380

381-
> 1.0.22+
382-
383381
- **Type:** `Object`
384382

385383
- **Restriction:** only respected in instance creation via `new`.
@@ -499,6 +497,325 @@ type: api
499497

500498
- **See also:** [Instance Methods - vm.$watch](#vm-watch)
501499

500+
## Options / DOM
501+
502+
### el
503+
504+
- **Type:** `String | HTMLElement | Function`
505+
506+
- **Restriction:** only accepts type `Function` when used in a component definition.
507+
508+
- **Details:**
509+
510+
Provide the Vue instance an existing DOM element to mount on. It can be a CSS selector string, an actual HTMLElement, or a function that returns an HTMLElement. Note that the provided element merely serves as a mounting point; it will be replaced if a template is also provided. The resolved element will be accessible as `vm.$el`.
511+
512+
When used in `Vue.extend`, a function must be provided so each instance gets a separately created element.
513+
514+
If this option is available at instantiation, the instance will immediately enter compilation; otherwise, the user will have to explicitly call `vm.$mount()` to manually start the compilation.
515+
516+
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
517+
518+
### template
519+
520+
- **Type:** `String`
521+
522+
- **Details:**
523+
524+
A string template to be used as the markup for the Vue instance. The template will **replace** the mounted element. Any existing markup inside the mounted element will be ignored, unless content distribution slots are present in the template.
525+
526+
If the string starts with `#` it will be used as a querySelector and use the selected element's innerHTML as the template string. This allows the use of the common `<script type="x-template">` trick to include templates.
527+
528+
- **See also:**
529+
- [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
530+
- [Content Distribution](/guide/components.html#Content-Distribution-with-Slots)
531+
- [Fragment Instance](/guide/components.html#Fragment-Instance)
532+
533+
### render
534+
535+
- **Type:** `Function`
536+
537+
- **Details:**
538+
539+
An alternative to string templates allowing you to leverage the full programmatic power of JavaScript. The render function receives a `createElement` method as it's first argument used to create `VNode`s.
540+
541+
- **See also:**
542+
- [Render Functions](/guide/render-function)
543+
544+
## Options / Lifecycle Hooks
545+
546+
### beforeCreate
547+
548+
- **Type:** `Function`
549+
550+
- **Details:**
551+
552+
Called synchronously after the instance has just been initialized, before data observation and event/watcher setup.
553+
554+
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
555+
556+
### created
557+
558+
- **Type:** `Function`
559+
560+
- **Details:**
561+
562+
Called synchronously after the instance is created. At this stage, the instance has finished processing the options which means the following have been set up: data observation, computed properties, methods, watch/event callbacks. However, DOM compilation has not been started, and the `$el` property will not be available yet.
563+
564+
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
565+
566+
### beforeMount
567+
568+
- **Type:** `Function`
569+
570+
- **Details:**
571+
572+
Called after the template has just been compiled, before `vm.$el` is created.
573+
574+
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
575+
576+
### mounted
577+
578+
- **Type:** `Function`
579+
580+
- **Details:**
581+
582+
Called after the instance has just been mounted where `el` is replaced by the newly created `vm.$el`.
583+
584+
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
585+
586+
### beforeUpdate
587+
588+
- **Type:** `Function`
589+
590+
- **Details:**
591+
592+
Called when the data changes, before the virtual DOM is re-rendered and patched.
593+
594+
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
595+
596+
### updated
597+
598+
- **Type:** `Function`
599+
600+
- **Details:**
601+
602+
Called after a data change causes the virtual DOM to be re-rendered and patched.
603+
604+
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
605+
606+
### activated
607+
608+
- **Type:** `Function`
609+
610+
- **Details:**
611+
612+
Called after a dynamic component is activated, allowing you to perform any necessary asynchronous operations before it should be swapped in.
613+
614+
The `activated` hook is only respected during dynamic component swapping or the initial render for static components - it does not affect manual insertions with instance methods.
615+
616+
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
617+
618+
### deactivated
619+
620+
- **Type:** `Function`
621+
622+
- **Details:**
623+
624+
Called after the dynamic component has been swapped out.
625+
626+
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
627+
628+
### beforeDestroy
629+
630+
- **Type:** `Function`
631+
632+
- **Details:**
633+
634+
Called right before a Vue instance is destroyed. At this stage the instance is still fully functional.
635+
636+
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
637+
638+
### destroyed
639+
640+
- **Type:** `Function`
641+
642+
- **Details:**
643+
644+
Called after a Vue instance has been destroyed. When this hook is called, all bindings and directives of the Vue instance have been unbound and all child Vue instances have also been destroyed.
645+
646+
Note if there is a leaving transition, the `destroyed` hook is called **after** the transition has finished.
647+
648+
- **See also:** [Lifecycle Diagram](/guide/instance.html#Lifecycle-Diagram)
649+
650+
## Options / Assets
651+
652+
### directives
653+
654+
- **Type:** `Object`
655+
656+
- **Details:**
657+
658+
A hash of directives to be made available to the Vue instance.
659+
660+
- **See also:**
661+
- [Custom Directives](/guide/custom-directive.html)
662+
- [Assets Naming Convention](/guide/components.html#Assets-Naming-Convention)
663+
664+
### filters
665+
666+
- **Type:** `Object`
667+
668+
- **Details:**
669+
670+
A hash of filters to be made available to the Vue instance.
671+
672+
- **See also:**
673+
- [Custom Filters](/guide/custom-filter.html)
674+
- [Assets Naming Convention](/guide/components.html#Assets-Naming-Convention)
675+
676+
### components
677+
678+
- **Type:** `Object`
679+
680+
- **Details:**
681+
682+
A hash of components to be made available to the Vue instance.
683+
684+
- **See also:**
685+
- [Components](/guide/components.html)
686+
687+
### transitions
688+
689+
- **Type:** `Object`
690+
691+
- **Details:**
692+
693+
A hash of transitions to be made available to the Vue instance.
694+
695+
- **See also:**
696+
- [Transitions](/guide/transitions.html)
697+
698+
## Options / Misc
699+
700+
### parent
701+
702+
- **Type:** `Vue instance`
703+
704+
- **Details:**
705+
706+
Specify the parent instance for the instance to be created. Establishes a parent-child relationship between the two. The parent will be accessible as `this.$parent` for the child, and the child will be pushed into the parent's `$children` array.
707+
708+
- **See also:** [Parent-Child Communication](/guide/components.html#Parent-Child-Communication)
709+
710+
### mixins
711+
712+
- **Type:** `Array`
713+
714+
- **Details:**
715+
716+
The `mixins` option accepts an array of mixin objects. These mixin objects can contain instance options just like normal instance objects, and they will be merged against the eventual options using the same option merging logic in `Vue.extend()`. e.g. If your mixin contains a created hook and the component itself also has one, both functions will be called.
717+
718+
Mixin hooks are called in the order they are provided, and called before the component's own hooks.
719+
720+
- **Example:**
721+
722+
``` js
723+
var mixin = {
724+
created: function () { console.log(1) }
725+
}
726+
var vm = new Vue({
727+
created: function () { console.log(2) },
728+
mixins: [mixin]
729+
})
730+
// -> 1
731+
// -> 2
732+
```
733+
734+
- **See also:** [Mixins](/guide/mixins.html)
735+
736+
### name
737+
738+
- **Type:** `String`
739+
740+
- **Restriction:** only respected when used in `Vue.extend()`.
741+
742+
- **Details:**
743+
744+
Allow the component to recursively invoke itself in its template. Note that when a component is registered globally with `Vue.component()`, the global ID is automatically set as its name.
745+
746+
Another benefit of specifying a `name` option is console inspection. When inspecting an extended Vue component in the console, the default constructor name is `VueComponent`, which isn't very informative. By passing in an optional `name` option to `Vue.extend()`, you will get a better inspection output so that you know which component you are looking at. The string will be camelized and used as the component's constructor name.
747+
748+
- **Example:**
749+
750+
``` js
751+
var Ctor = Vue.extend({
752+
name: 'stack-overflow',
753+
template:
754+
'<div>' +
755+
// recursively invoke self
756+
'<stack-overflow></stack-overflow>' +
757+
'</div>'
758+
})
759+
760+
// this will actually result in a max stack size exceeded
761+
// error, but let's assume it works...
762+
var vm = new Ctor()
763+
764+
console.log(vm) // -> StackOverflow {$el: null, ...}
765+
```
766+
767+
### extends
768+
769+
- **Type:** `Object | Function`
770+
771+
- **Details:**
772+
773+
Allows declaratively extending another component (could be either a plain options object or a constructor) without having to use `Vue.extend`. This is primarily intended to make it easier to extend between single file components.
774+
775+
This is similar to `mixins`, the difference being that the component's own options takes higher priority than the source component being extended.
776+
777+
- **Example:**
778+
779+
``` js
780+
var CompA = { ... }
781+
782+
// extend CompA without having to call Vue.extend on either
783+
var CompB = {
784+
extends: CompA,
785+
...
786+
}
787+
```
788+
789+
### delimiters
790+
791+
- **Type:** `Array<String>`
792+
793+
- **default:** `["{{", "}}"]`
794+
795+
- **Details:**
796+
797+
Change the plain text interpolation delimiters. This option is only available in the standalone build.
798+
799+
- **Example:**
800+
801+
``` js
802+
new Vue({
803+
delimiters: ['${', '}']
804+
})
805+
806+
// Delimiters changed to ES6 template string style
807+
```
808+
809+
### functional
810+
811+
- **Type:** `boolean`
812+
813+
- **Details:**
814+
815+
Causes a component to be stateless (no `data`) and instanceless (no `this` context). They are simply a `render` function that returns virtual nodes making them much cheaper to render.
816+
817+
- **See also:** [Functional Components](/guide/render-function.html#Functional-Components)
818+
502819
## Instance Properties
503820

504821
### vm.$data
@@ -832,9 +1149,9 @@ type: api
8321149
<h3 id="vm-forceUpdate">vm.$forceUpdate( )</h3>
8331150

8341151
- **Usage:**
835-
1152+
8361153
The Vue instance will be forced the re-render.
837-
1154+
8381155
<p class="tip">Note: This method have an influence on your application performance degradation. The excessive call is no recommended.</p>
8391156

8401157
<h3 id="vm-destroy">vm.$destroy( )</h3>
@@ -1071,7 +1388,7 @@ type: api
10711388

10721389
<!-- prop binding. "prop" must be declared in my-component. -->
10731390
<my-component :prop="someThing"></my-component>
1074-
1391+
10751392
<!-- XLink -->
10761393
<svg><a :xlink:special="foo"></a></svg>
10771394
```

src/guide/comparison.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ React and Vue share many similarities. They both:
1818
- provide reactive and composable view components
1919
- maintain focus in the core library, with concerns such as routing and global state management handled by companion libraries
2020

21-
There are, of course, many differences as well:
21+
Being so similar in scope, we've put more time into fine-tuning this comparison than any other. We want to ensure not only technical accuracy, but also balance. We point out where React outshines Vue, for example in the richness of their ecosystem and abundance of their custom renderers.
22+
23+
The React community [has been instrumental](https://github.com/vuejs/vuejs.org/issues/364) in helping us achieve this balance, with special thanks to Dan Abramov from the React team. He was extremely generous with his time and considerable expertise to help us refine this document until we were [both happy](https://github.com/vuejs/vuejs.org/issues/364#issuecomment-244575740) with the final result.
24+
25+
With that said, we hope you can feel confident in the fairness of the review below as we explore the differences between these two libraries.
2226

2327
### Performance Profiles
2428

@@ -99,7 +103,7 @@ In React, everything is Just JavaScript, which sounds very simple and elegant -
99103

100104
#### JSX vs Templates
101105

102-
In React, all components express their UI within render functions using JSX, a declarative XML-like syntax that works within Javascript. Here's an example, [vetted by the React community](https://github.com/vuejs/vuejs.org/pull/371):
106+
In React, all components express their UI within render functions using JSX, a declarative XML-like syntax that works within Javascript. Here's an example, [vetted by the React community](https://github.com/vuejs/vuejs.org/issues/364#issuecomment-244582684):
103107

104108
``` jsx
105109
render () {
@@ -192,7 +196,7 @@ Finally, just as with HTML, you also have the option of writing your CSS using a
192196

193197
For large applications, both Vue and React offer robust routing solutions. The React community has also been very innovative in terms of state management solutions (e.g. Flux/Redux). These state management patterns and [even Redux itself](https://github.com/egoist/revue) can be easily integrated into Vue applications. In fact, Vue has even taken this model a step further with [Vuex](https://github.com/vuejs/vuex), an Elm-inspired state management solution that integrates deeply into Vue that we think offers a superior development experience.
194198

195-
Another important difference between these offerings is that Vue's companion libraries for state management and routing (among [other concerns](https://github.com/vuejs)) are all officially supported and kept up-to-date with the core library. React instead chooses to leave these concerns to the community, creating a more fragmented ecosystem.
199+
Another important difference between these offerings is that Vue's companion libraries for state management and routing (among [other concerns](https://github.com/vuejs)) are all officially supported and kept up-to-date with the core library. React instead chooses to leave these concerns to the community, creating a more fragmented ecosystem. Being more popular though, React's ecosystem is considerably richer than Vue's.
196200

197201
Finally, Vue offers a [CLI project generator](https://github.com/vuejs/vue-cli) that makes it trivially easy to start a new project using your choice of build system, including [Webpack](https://github.com/vuejs-templates/webpack), [Browserify](https://github.com/vuejs-templates/browserify), or even [no build system](https://github.com/vuejs-templates/simple). React is also making strides in this area with [create-react-app](https://github.com/facebookincubator/create-react-app), but it currently has a few limitations:
198202

src/guide/components.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ When a prop validation fails, Vue will refuse to set the value on the child comp
490490

491491
A child component holds access to its parent component as `this.$parent`. A root Vue instance will be available to all of its descendants as `this.$root`. Each parent component has an array, `this.$children`, which contains all its child components.
492492

493+
When you'd like to access a specific child, you can give that component a `ref` attribute (e.g. `ref="myChild"`), which makes the component instance available via `this.$refs.myChild`.
494+
493495
<p class="tip">These properties are made available as an escape hatch to accomodate extreme edge cases. They are not the correct way to access and mutate components in the vast majority of circumstances and if abused, can make your components much more difficult to reason about.</p>
494496

495497
Instead, prefer passing data down explicitly using props. Where data must be shared and mutated by multiple components, a parent component can be used to manage state in a single location. To mutate parent state, custom events can be emitted that parents may choose to listen to or mutation methods can be passed to child components.

0 commit comments

Comments
 (0)