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/migration/async-components.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ const asyncPage = {
30
30
}
31
31
```
32
32
33
-
## Current Syntax
33
+
## 3.x Syntax
34
34
35
35
Now, in Vue 3, since functional components are defined as pure functions, async components definitions need to be explicitly defined by wrapping it in a new `defineAsyncComponent` helper:
Another change that has been made from v2 is that the `component` option is now renamed to `loader` in order to accurately communicate that a component definition cannot be provided directly.
55
+
Another change that has been made from 2.x is that the `component` option is now renamed to `loader` in order to accurately communicate that a component definition cannot be provided directly.
Copy file name to clipboardExpand all lines: src/guide/migration/custom-directives.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ Here is a quick summary of what has changed:
9
9
10
10
For more information, read on!
11
11
12
-
## Previous Syntax
12
+
## 2.x Syntax
13
13
14
14
In Vue 2, custom directives were created by using the hooks listed below to target an element’s lifecycle, all of which are optional:
15
15
@@ -35,7 +35,7 @@ Vue.directive('highlight', {
35
35
36
36
Here, in the initial setup for this element, the directive binds a style by passing in a value, that can be updated to different values through the application.
37
37
38
-
## Current Syntax
38
+
## 3.x Syntax
39
39
40
40
In Vue 3, however, we’ve created a more cohesive API for custom directives. As you can see, they differ greatly from our component lifecycle methods even though we’re hooking into similar events. We’ve now unified them like so:
Copy file name to clipboardExpand all lines: src/guide/migration/events-api.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -10,9 +10,9 @@ types:
10
10
11
11
`$on`, `$off` and `$once` instance methods are removed. Vue instances no longer implement the event emitter interface.
12
12
13
-
## Previous Syntax
13
+
## 2.x Syntax
14
14
15
-
In v2, Vue instance could be used to trigger handlers attached imperatively via the event emitter API (`$on`, `$off` and `$once`). This was used to create _event hubs_ to create global event listeners used across the whole application:
15
+
In 2.x, Vue instance could be used to trigger handlers attached imperatively via the event emitter API (`$on`, `$off` and `$once`). This was used to create _event hubs_ to create global event listeners used across the whole application:
Copy file name to clipboardExpand all lines: src/guide/migration/fragments.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
In Vue 3, components now have official support for multi-root node components, i.e., fragments!
6
6
7
-
## Previous Syntax
7
+
## 2.x Syntax
8
8
9
9
In 2.x, multi-root components were not supported and would emit a warning when a user accidentally created one. As a result, many components are wrapped in a single `<div>` in order to fix this error.
10
10
@@ -19,7 +19,7 @@ In 2.x, multi-root components were not supported and would emit a warning when a
19
19
</template>
20
20
```
21
21
22
-
## Current Syntax
22
+
## 3.x Syntax
23
23
24
24
In 3.x, components now can have multiple root nodes! However, this does require developers to explicitly define where attributes should be distributed.
Copy file name to clipboardExpand all lines: src/guide/migration/functional-components.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
In terms of what has changed, at a high level:
6
6
7
-
- Performance gains from v2 for functional components are now negligible in v3, so we recommend just using stateful components
7
+
- Performance gains from 2.x for functional components are now negligible in 3.x, so we recommend just using stateful components
8
8
- Functional components can only be created using a plain function that receives `props` and `context` (i.e., `slots`, `attrs`, `emit`)
9
9
-**DEPRECATED:**`functional` attribute on single-file component (SFC) `<template>` is deprecated
10
10
-**DEPRECATED:**`{ functional: true }` option in components created by functions is deprecated
@@ -22,9 +22,9 @@ However, in Vue 3, the performance of stateful components has improved to the po
22
22
23
23
As a result, the only remaining use case for functional components is simple components, such as a component to create a dynamic heading. Otherwise, it is recommended to use stateful components as you normally would.
24
24
25
-
## Previous Syntax
25
+
## 2.x Syntax
26
26
27
-
Using the `<dynamic-heading>` component, which is responsible for rendering out the appropriate heading (i.e., `h1`, `h2`, `h3`, etc.), this could have been written as a single-file component in v2 as:
27
+
Using the `<dynamic-heading>` component, which is responsible for rendering out the appropriate heading (i.e., `h1`, `h2`, `h3`, etc.), this could have been written as a single-file component in 2.x as:
28
28
29
29
```js
30
30
// Vue 2 Functional Component Example
@@ -56,7 +56,7 @@ export default {
56
56
</script>
57
57
```
58
58
59
-
## Current Syntax
59
+
## 3.x Syntax
60
60
61
61
### Components Created by Functions
62
62
@@ -82,7 +82,7 @@ export default GreetingMessage
82
82
83
83
### Single File Components (SFCs)
84
84
85
-
In v3, the performance difference between stateful and functional components has been drastically reduced and will be insignificant in most use cases. As a result, the migration path for developers using `functional` on SFCs is to remove the attribute. No additional work required.
85
+
In 3.x, the performance difference between stateful and functional components has been drastically reduced and will be insignificant in most use cases. As a result, the migration path for developers using `functional` on SFCs is to remove the attribute. No additional work required.
86
86
87
87
Using our `<dynamic-heading>` example from before, here is how it would look now.
Copy file name to clipboardExpand all lines: src/guide/migration/keycode-modifiers.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ Here is a quick summary of what has changed:
7
7
-**BREAKING**: Using numbers, i.e. keyCodes, as `v-on` modifiers is no longer supported
8
8
-**BREAKING**: `config.keyCodes` is no longer supported
9
9
10
-
## Previous Syntax
10
+
## 2.x Syntax
11
11
12
12
In Vue 2, `keyCodes` were supported as a way to modify a `v-on` method.
13
13
@@ -35,7 +35,7 @@ Vue.config.keyCodes = {
35
35
<inputv-on:keyup.f1="showHelpText" />
36
36
```
37
37
38
-
## Current Syntax
38
+
## 3.x Syntax
39
39
40
40
Since [`KeyboardEvent.keyCode` has been deprecated](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode), it no longer makes sense for Vue 3 to continue supporting this as well. As a result, it is now recommended to use the kebab-case name for any key you want to use as a modifier.
Copy file name to clipboardExpand all lines: src/guide/migration/render-function-api.md
+14-13Lines changed: 14 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ For more information, read on!
14
14
15
15
## Render Function Argument
16
16
17
-
### Previous Syntax
17
+
### 2.x Syntax
18
18
19
19
In 2.x, the `render` function would automatically receive the `h` function (which is a conventional alias for `createElement`) as an argument:
20
20
@@ -27,7 +27,7 @@ export default {
27
27
}
28
28
```
29
29
30
-
### Current Syntax
30
+
### 3.x Syntax
31
31
32
32
In 3.x, `h` is now globally imported instead of being automatically passed as an argument.
33
33
@@ -44,7 +44,7 @@ export default {
44
44
45
45
## Render Function Signature Change
46
46
47
-
### Previous Syntax
47
+
### 2.x Syntax
48
48
49
49
In 2.x, the `render` function automatically received arguments such as `h`.
50
50
@@ -57,7 +57,7 @@ export default {
57
57
}
58
58
```
59
59
60
-
### Current Syntax
60
+
### 3.x Syntax
61
61
62
62
In 3.x, since the `render` function no longer receives any arguments, it will primarily be used inside of the `setup()` function. This has the added benefit of gaining access to reactive state and functions declared in scope, as well as the arguments passed to `setup()`.
63
63
@@ -75,13 +75,14 @@ export default {
75
75
}
76
76
77
77
// return the render function
78
-
return () =>h(
79
-
'div',
80
-
{
81
-
onClick: increment
82
-
},
83
-
state.count
84
-
)
78
+
return () =>
79
+
h(
80
+
'div',
81
+
{
82
+
onClick: increment
83
+
},
84
+
state.count
85
+
)
85
86
}
86
87
}
87
88
```
@@ -90,7 +91,7 @@ For more information on how `setup()` works, see our [Composition API Guide](/gu
90
91
91
92
## VNode Props Format
92
93
93
-
### Previous Syntax
94
+
### 2.x Syntax
94
95
95
96
In 2.x, `domProps` contained a nested list within the VNode props:
96
97
@@ -106,7 +107,7 @@ In 2.x, `domProps` contained a nested list within the VNode props:
106
107
}
107
108
```
108
109
109
-
### Current Syntax
110
+
### 3.x Syntax
110
111
111
112
In 3.x, the entire VNode props structure is flattened. Using the example from above, here is what it would look like now.
Copy file name to clipboardExpand all lines: src/guide/migration/treeshaking.md
+17-18Lines changed: 17 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Global API Treeshaking
2
2
3
-
## Previous Syntax
3
+
## 2.x Syntax
4
4
5
5
If you’ve ever had to manually manipulate DOM in Vue, you might have come across this pattern:
6
6
@@ -20,22 +20,22 @@ import { MyComponent } from './MyComponent.vue'
20
20
21
21
test('an async feature', async () => {
22
22
constwrapper=shallowMount(MyComponent)
23
-
23
+
24
24
// execute some DOM-related tasks
25
25
26
26
awaitwrapper.vm.$nextTick()
27
27
28
-
// run your assertions
28
+
// run your assertions
29
29
})
30
30
```
31
31
32
-
`Vue.nextTick()` is a global API exposed directly on a single Vue object – in fact, the instance method `$nextTick()` is just a handy wrapper around `Vue.nextTick()` with the callback’s `this` context automatically bound to the current Vue instance for convenience.
32
+
`Vue.nextTick()` is a global API exposed directly on a single Vue object – in fact, the instance method `$nextTick()` is just a handy wrapper around `Vue.nextTick()` with the callback’s `this` context automatically bound to the current Vue instance for convenience.
33
33
34
-
But what if you’ve never had to deal with manual DOM manipulation, nor are you using or testing async components in our app? Or, what if, for whatever reason, you prefer to use the good old `window.setTimeout()` instead? In such a case, the code for `nextTick()` will become dead code – that is, code that’s written but never used. And dead code is hardly a good thing, especially in our client-side context where every kilobyte matters.
34
+
But what if you’ve never had to deal with manual DOM manipulation, nor are you using or testing async components in our app? Or, what if, for whatever reason, you prefer to use the good old `window.setTimeout()` instead? In such a case, the code for `nextTick()` will become dead code – that is, code that’s written but never used. And dead code is hardly a good thing, especially in our client-side context where every kilobyte matters.
35
35
36
-
Module bundlers like [webpack](https://webpack.js.org/) support [tree-shaking](https://webpack.js.org/guides/tree-shaking/), which is a fancy term for “dead code elimination.” Unfortunately, due to how the code is written in previous Vue versions, global APIs like `Vue.nextTick()` are not tree-shakeable and will be included in the final bundle regardless of where they are actually used or not.
36
+
Module bundlers like [webpack](https://webpack.js.org/) support [tree-shaking](https://webpack.js.org/guides/tree-shaking/), which is a fancy term for “dead code elimination.” Unfortunately, due to how the code is written in previous Vue versions, global APIs like `Vue.nextTick()` are not tree-shakeable and will be included in the final bundle regardless of where they are actually used or not.
37
37
38
-
## Current Syntax
38
+
## 3.x Syntax
39
39
40
40
In Vue 3, the global and internal APIs have been restructured with tree-shaking support in mind. As a result, the global APIs can now only be accessed as named exports for the ES Modules build. For example, our previous snippets should now look like this:
Calling `Vue.nextTick()` directly will now result in the infamous `undefined is not a function` error.
68
+
Calling `Vue.nextTick()` directly will now result in the infamous `undefined is not a function` error.
69
69
70
70
With this change, provided the module bundler supports tree-shaking, global APIs that are not used in a Vue application will be eliminated from the final bundle, resulting in an optimal file size.
71
71
72
72
## Affected APIs
73
73
74
74
These global APIs in Vue 2.x are affected by this change:
75
75
76
-
*`Vue.nextTick`
77
-
*`Vue.observable` (replaced by `Vue.reactive`)
78
-
*`Vue.version`
79
-
*`Vue.compile` (only in full builds)
80
-
*`Vue.set` (only in compat builds)
81
-
*`Vue.delete` (only in compat builds)
82
-
76
+
-`Vue.nextTick`
77
+
-`Vue.observable` (replaced by `Vue.reactive`)
78
+
-`Vue.version`
79
+
-`Vue.compile` (only in full builds)
80
+
-`Vue.set` (only in compat builds)
81
+
-`Vue.delete` (only in compat builds)
83
82
84
83
## Internal Helpers
85
84
@@ -103,9 +102,9 @@ export function render() {
103
102
}
104
103
```
105
104
106
-
This essentially means the `Transition` component only gets imported when the application actually makes use of it. In other words, if the application doesn’t have any `<transition>` component, the code supporting this feature will not be present in the final bundle.
105
+
This essentially means the `Transition` component only gets imported when the application actually makes use of it. In other words, if the application doesn’t have any `<transition>` component, the code supporting this feature will not be present in the final bundle.
107
106
108
-
With global tree-shaking, the user only “pay” for the features they actually use. Even better, knowing that optional features won't increase the bundle size for applications not using them, framework size has become much less a concern for additional core features in the future, if at all.
107
+
With global tree-shaking, the user only “pay” for the features they actually use. Even better, knowing that optional features won't increase the bundle size for applications not using them, framework size has become much less a concern for additional core features in the future, if at all.
109
108
110
109
::: warning Important
111
110
The above only applies to the [ES Modules builds](/guide/installation.html#explanation-of-different-builds) for use with tree-shaking capable bundlers - the UMD build still includes all features and exposes everything on the Vue global variable (and the compiler will produce appropriate output to use APIs off the global instead of importing).
@@ -153,7 +152,7 @@ module.exports = {
153
152
154
153
This will tell webpack to treat the Vue module as an external library and not bundle it.
155
154
156
-
If your module bundler of choice happens to be [Rollup](https://rollupjs.org/), you basically get the same effect for free, as by default Rollup will treat absolute module IDs (`'vue'` in our case) as external dependencies and not include them in the final bundle. During bundling though, it might emit a [“Treating vue as external dependency”](https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency) warning, which can be suppressed with the `external` option:
155
+
If your module bundler of choice happens to be [Rollup](https://rollupjs.org/), you basically get the same effect for free, as by default Rollup will treat absolute module IDs (`'vue'` in our case) as external dependencies and not include them in the final bundle. During bundling though, it might emit a [“Treating vue as external dependency”](https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency) warning, which can be suppressed with the `external` option:
Copy file name to clipboardExpand all lines: src/guide/migration/v-model.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -21,9 +21,9 @@ In 2.2 we introduced the `model` component option that allows the component to c
21
21
22
22
With Vue 3, the API for two-way data binding is being standardized in order to reduce confusion and to allow developers more flexibility with the `v-model` directive.
23
23
24
-
## Previous Syntax
24
+
## 2.x Syntax
25
25
26
-
In v2, using a `v-model` on a component was an equivalent of passing a `value` prop and emitting an `input` event:
26
+
In 2.x, using a `v-model` on a component was an equivalent of passing a `value` prop and emitting an `input` event:
27
27
28
28
```html
29
29
<ChildComponentv-model="pageTitle" />
@@ -87,9 +87,9 @@ For convenience, we had a shorthand for this pattern with the .sync modifier:
87
87
<ChildComponent:title.sync="pageTitle" />
88
88
```
89
89
90
-
## Current Syntax
90
+
## 3.x Syntax
91
91
92
-
In v3`v-model` on the custom component is an equivalent of passing a `modelValue` prop and emitting an `update:modelValue` event:
92
+
In 3.x`v-model` on the custom component is an equivalent of passing a `modelValue` prop and emitting an `update:modelValue` event:
93
93
94
94
```html
95
95
<ChildComponentv-model="pageTitle" />
@@ -130,7 +130,7 @@ This also serves as a replacement to `.sync` modifier and allows us to have mult
130
130
131
131
### `v-model` modifiers
132
132
133
-
In addition to v2 hard-coded `v-model` modifiers like `.trim`, now v3 supports custom modifiers:
133
+
In addition to 2.x hard-coded `v-model` modifiers like `.trim`, now 3.x supports custom modifiers:
0 commit comments