Skip to content

Commit 6bbf7f1

Browse files
committed
Add documentation, closes vuejs#535
1 parent 5484bb7 commit 6bbf7f1

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

README.md

+42-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import VueCompositionAPI from '@vue/composition-api'
2929
Vue.use(VueCompositionAPI)
3030
```
3131

32-
```js
32+
```jsgit@github.com:phbender/composition-api.git
3333
// use the APIs
3434
import { ref, reactive } from '@vue/composition-api'
3535
```
@@ -410,6 +410,47 @@ defineComponent({
410410

411411
</details>
412412

413+
### Global state
414+
415+
<details>
416+
<summary>When you use `ref` oder `reactive` before the plugin has been initialized, you may encounter an error `Error: [vue-composition-api] No vue dependency found.`.</summary>
417+
</details>
418+
419+
In your `main.js`:
420+
421+
```js
422+
import Vue from 'vue';
423+
import './composition-api';
424+
425+
import './useSomething';
426+
427+
// import and create your app etc.
428+
```
429+
430+
Your `composition-api.js`:
431+
432+
```js
433+
import Vue from 'vue';
434+
import VueCompositionAPI from '@vue/composition-api';
435+
Vue.use(VueCompositionAPI);
436+
```
437+
438+
Your `useSomething.js`:
439+
440+
```js
441+
import { ref } from '@vue/composition-api';
442+
443+
const someState = ref(0);
444+
445+
const someFeature = () => {
446+
someState.value = someState.value + 1;
447+
}
448+
449+
export {
450+
someState,
451+
someFeature
452+
}
453+
```
413454

414455

415456
### Missing APIs

0 commit comments

Comments
 (0)