@@ -35,7 +35,7 @@ import { ref, reactive } from '@vue/composition-api'
35
35
36
36
### CDN
37
37
38
- Add the following lines in your ` <head> ` to import Vue and ` @vue/composition-api ` .
38
+ Include ` @vue/composition-api ` after Vue and it will install itself automatically .
39
39
40
40
<!-- cdn-links-start-->
41
41
``` html
@@ -44,15 +44,9 @@ Add the following lines in your `<head>` to import Vue and `@vue/composition-api
44
44
```
45
45
<!-- cdn-links-end-->
46
46
47
- ` @vue/composition-api ` will be exposed to global variable ` window.vueCompositionApi ` and you have to install it before using the APIs.
47
+ ` @vue/composition-api ` will be exposed to global variable ` window.vueCompositionApi ` .
48
48
49
- ``` js
50
- // install the plugin
51
- Vue .use (vueCompositionApi .default )
52
- ```
53
-
54
- ``` js
55
- // use the APIs
49
+ ``` ts
56
50
const { ref, reactive } = vueCompositionApi
57
51
```
58
52
@@ -66,14 +60,9 @@ To let TypeScript properly infer types inside Vue component options, you need to
66
60
``` ts
67
61
import { defineComponent } from ' @vue/composition-api'
68
62
69
- const ComponentA = defineComponent ({
63
+ export default defineComponent ({
70
64
// type inference enabled
71
65
})
72
-
73
- const ComponentB = {
74
- // this will NOT have type inference,
75
- // because TypeScript can't tell this is options for a Vue component.
76
- }
77
66
```
78
67
79
68
### JSX/TSX
@@ -259,11 +248,18 @@ export default {
259
248
}
260
249
```
261
250
262
- If you really want to use template refs in this case, you can access ` vm.$refs ` via ` SetupContext.refs ` .
251
+ <details >
252
+ <summary ><code >$refs</code > accessing workaround
253
+ </summary >
254
+
255
+ <br >
263
256
264
257
> :warning : ** Warning** : The ` SetupContext.refs ` won't exist in ` Vue 3.0 ` . ` @vue/composition-api ` provide it as a workaround here.
265
258
266
- ``` js
259
+ If you really want to use template refs in this case, you can access ` vm.$refs ` via ` SetupContext.refs ` .
260
+
261
+
262
+ ``` jsx
267
263
export default {
268
264
setup (initProps , setupContext ) {
269
265
const refs = setupContext .refs
@@ -287,9 +283,6 @@ You may also need to augment the `SetupContext` when working with TypeScript:
287
283
288
284
``` ts
289
285
import Vue from ' vue'
290
- import VueCompositionApi from ' @vue/composition-api'
291
-
292
- Vue .use (VueCompositionApi )
293
286
294
287
declare module ' @vue/composition-api' {
295
288
interface SetupContext {
@@ -298,6 +291,9 @@ declare module '@vue/composition-api' {
298
291
}
299
292
```
300
293
294
+ </details >
295
+
296
+
301
297
## SSR
302
298
303
299
Even if there is no definitive Vue 3 API for SSR yet, this plugin implements the ` onServerPrefetch ` lifecycle hook that allows you to use the ` serverPrefetch ` hook found in the classic API.
0 commit comments