You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/guide/comparison.md
+4-16Lines changed: 4 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ In React, everything is Just JavaScript, which sounds very simple and elegant -
50
50
51
51
#### JSX vs Templates
52
52
53
-
Let's dive into a simple React render function, kindly [provided by Dan Abramov](https://github.com/vuejs/vuejs.org/pull/371):
53
+
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):
54
54
55
55
```jsx
56
56
render () {
@@ -77,18 +77,6 @@ render () {
77
77
}
78
78
```
79
79
80
-
This is an extremely common use case, but using JSX, there are a few problems that may not be immediately obvious:
81
-
82
-
-__Decisions, Decisions__: Despite the simplicity of the above code, it actually went through a series of iterations until Dan Abramov kindly ended the bikeshedding with a definitive version we could settle on. It's interesting to note though, that none of the other recommended solutions we saw were identical to Dan's. This is because JSX, just like JavaScript, requires frequent compromises between readability and declarativeness that come down to individual judgment calls. These are some of the factors to be considered:
83
-
84
-
- Not everything is an expression in JavaScript, making some common language features such as if statements a bit awkward to embed within JSX. There are sometimes alternatives which _are_ expressions, such as a ternary in this case, but many consider ternaries to be less readable.
85
-
- When nesting JSX within JavaScript within JSX (etc), visual noise is created with curly braces and often parentheses. Different people make different decisions in how they prefer to minimize that noise.
86
-
- To address the above two concerns, the simplest option is to do as much as possible outside JSX, then only embed a variable, like `children` in the example above. The downside is that the render function then ceases to be a purely declarative description of the generated view, instead becoming an imperative list of operations with a declarative (but less descriptive) result. Other alternatives include:
87
-
- Generating parts of the UI in helper functions, then calling them in the main render function. The downside is that visually parsing a component takes longer, as one has to jump around a lot more.
88
-
- Breaking a component out into more, smaller components (e.g. `ListContainer`, `List`, `ListItem`, and `EmptyList`). This has advantages beyond making render functions easier to read as an application grows in complexity. However, if it never grows complex enough to otherwise warrant the split, it's a lot of added boilerplate.
89
-
90
-
-__Learning Curve__: While JSX looks similar to HTML, it's definitely not and there are edge cases to keep in mind - one being the use of `className` instead of `class`, such as in the example. To get this code reading as nicely as possible, it's also necessary to use ES2015+ language features, which many developers have not mastered yet. Combined, these two caveats significantly limit the pool of people that can contribute to the frontend. You eliminate designers, intermediate JavaScript developers, or even advanced JavaScript developers that aren't yet familiar with the quirks of React's JSX.
91
-
92
80
In Vue, we also have [render functions](render-function.html) and even [support JSX](render-function.html#JSX), because sometimes it is useful to have the power of a full programming language. Render functions are not recommended for most components however.
93
81
94
82
Instead, we offer templates as a simpler alternative:
@@ -116,13 +104,13 @@ A few advantages here:
116
104
117
105
This is not only much easier for the developer that's writing it, but designers and less experienced developers will also find it much easier parsing and contributing code.
118
106
119
-
It doesn't end there though. By embracing HTML rather than trying to reinvent it, Vue also allows you to use preprocessors such as Pug (formerly known as Jade) in your templates.
107
+
It doesn't end there though. By embracing HTML rather than trying to reinvent it within JavaScript, Vue also allows you to use preprocessors such as Pug (formerly known as Jade) in your templates.
120
108
121
109
The React ecosystem also has [a project](https://wix.github.io/react-templates/) that allows you to write templates, but there are a few disadvantages:
122
110
123
-
- It's not nearly as feature-rich as Vue's templates
111
+
- It's not nearly as feature-rich as Vue's templating system
124
112
- It requires separating your HTML from component files
125
-
- Because it's a 3rd party library rather than an officially supported first-class citizen, it may or may not be kept up-to-date with React core into the future
113
+
- Because it's a 3rd party library rather than officially supported, it may or may not be kept up-to-date with React core into the future
Copy file name to clipboardExpand all lines: src/guide/custom-directive.md
-21Lines changed: 0 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -67,27 +67,6 @@ A directive definition object can provide several hook functions (all optional):
67
67
-`componentUpdated`: called after the component has completed an update cycle
68
68
-`unbind`: called only once, when the directive is unbound from the element.
69
69
70
-
For example:
71
-
72
-
```js
73
-
Vue.directive('demo', function (value) {
74
-
console.log(value) // "foo bar baz"
75
-
})
76
-
```
77
-
78
-
### Element Directives
79
-
80
-
In some cases, we may want our directive to be used in the form of a custom element rather than as an attribute. This is very similar to Angular's notion of "E" mode directives. Element directives provide a lighter-weight alternative to full-blown components (which are explained earlier in the guide). You can register a custom element directive like so:
81
-
82
-
```js
83
-
Vue.elementDirective('my-directive', {
84
-
// same API as normal directives
85
-
bind:function () {
86
-
// manipulate this.el...
87
-
}
88
-
})
89
-
```
90
-
91
70
We'll explore the arguments passed into these hooks (i.e. `el`, `binding`, `vnode`, and `oldVnode`) in the next section.
Copy file name to clipboardExpand all lines: src/guide/overview.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -243,4 +243,4 @@ You may have noticed that Vue components are very similar to **Custom Elements**
243
243
244
244
2. Vue components provide important features that are not available in plain custom elements, most notably cross-component data flow, custom event communication, and dynamic component switching with transition effects.
245
245
246
-
The component system is the foundation for building large apps with Vue. The Vue ecosystem also provides advanced tooling and officially supported companion libraries that can be combined to create a more framework-like system. The responsibilities of these libraries include [ajax](https://github.com/vuejs/vue-resource), [routing](https://github.com/vuejs/vue-router), [flux-like state management](https://github.com/vuejs/vuex), and [more](https://github.com/vuejs).
246
+
The component system is the foundation for building large apps with Vue. The Vue ecosystem also provides advanced tooling and officially supported companion libraries that can be combined to create a more framework-like system. The responsibilities of these libraries include [routing](https://github.com/vuejs/vue-router), [flux-like state management](https://github.com/vuejs/vuex), and [more](https://github.com/vuejs).
-[vue-router](https://github.com/vuejs/vue-router): The official router for Vue.js. Deeply integrated with Vue.js core to make building Single Page Applications a breeze.
128
128
129
-
-[vue-resource](https://github.com/vuejs/vue-resource): A plugin that provides services for making web requests and handle responses using a XMLHttpRequest or JSONP.
130
-
131
129
-[vue-async-data](https://github.com/vuejs/vue-async-data): Async data loading plugin.
132
130
133
131
-[vue-validator](https://github.com/vuejs/vue-validator): A plugin for form validations.
Everything the component needs is passed through `context`, which is an object containing:
320
320
321
321
-`props`: An object of the provided props
322
-
-`children`: A function returning the children
323
-
-`slots`: A function returning a slots object
322
+
-`children`: An array of the VNode children
323
+
-`slots`: A slots object
324
324
-`data`: The entire data object passed to the component
325
325
-`parent`: A reference to the parent component
326
326
@@ -370,7 +370,7 @@ Vue.component('smart-list', {
370
370
371
371
### `slots` vs `children`
372
372
373
-
You may wonder why we need both `slots` and `children`. Wouldn't `slots().default` be the same as `children`? In some cases, yes - but what if you have a functional component with the following children?
373
+
You may wonder why we need both `slots` and `children`. Wouldn't `slots.default` be the same as `children`? In some cases, yes - but what if you have a functional component with the following children?
374
374
375
375
```html
376
376
<my-functional-component>
@@ -381,7 +381,7 @@ You may wonder why we need both `slots` and `children`. Wouldn't `slots().defaul
381
381
</my-functional-component>
382
382
```
383
383
384
-
For this component, `children()` will give you both paragraphs, `slots().default` will give you only the second, and `slots().foo` will give you only the first. Having both `children` and `slots` therefore allows you to choose whether this component knows about a slot system or perhaps delegates that responsibility to another component by simply passing along `children`.
384
+
For this component, `children` will give you both paragraphs, `slots.default` will give you only the second, and `slots.foo` will give you only the first. Having both `children` and `slots` therefore allows you to choose whether this component knows about a slot system or perhaps delegates that responsibility to another component by simply passing along `children`.
0 commit comments