Skip to content

Commit b11f14c

Browse files
committed
docs: update
1 parent ff0143e commit b11f14c

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

README.md

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { ref, reactive } from '@vue/composition-api'
3535
3636
### CDN
3737

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.
3939

4040
<!--cdn-links-start-->
4141
```html
@@ -44,15 +44,9 @@ Add the following lines in your `<head>` to import Vue and `@vue/composition-api
4444
```
4545
<!--cdn-links-end-->
4646

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`.
4848

49-
```js
50-
// install the plugin
51-
Vue.use(vueCompositionApi.default)
52-
```
53-
54-
```js
55-
// use the APIs
49+
```ts
5650
const { ref, reactive } = vueCompositionApi
5751
```
5852

@@ -66,14 +60,9 @@ To let TypeScript properly infer types inside Vue component options, you need to
6660
```ts
6761
import { defineComponent } from '@vue/composition-api'
6862

69-
const ComponentA = defineComponent({
63+
export default defineComponent({
7064
// type inference enabled
7165
})
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-
}
7766
```
7867

7968
### JSX/TSX
@@ -259,11 +248,18 @@ export default {
259248
}
260249
```
261250

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>
263256

264257
> :warning: **Warning**: The `SetupContext.refs` won't exist in `Vue 3.0`. `@vue/composition-api` provide it as a workaround here.
265258
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
267263
export default {
268264
setup(initProps, setupContext) {
269265
const refs = setupContext.refs
@@ -287,9 +283,6 @@ You may also need to augment the `SetupContext` when working with TypeScript:
287283

288284
```ts
289285
import Vue from 'vue'
290-
import VueCompositionApi from '@vue/composition-api'
291-
292-
Vue.use(VueCompositionApi)
293286

294287
declare module '@vue/composition-api' {
295288
interface SetupContext {
@@ -298,6 +291,9 @@ declare module '@vue/composition-api' {
298291
}
299292
```
300293

294+
</details>
295+
296+
301297
## SSR
302298

303299
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

Comments
 (0)