Skip to content

Commit

Permalink
feat: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
chen season authored and chen season committed Feb 28, 2023
1 parent e2b6882 commit 98f0623
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,21 @@ You can use composition api `useProvideStores` or component `StoreProvider` to p

### `useProvideStores`

```ts
```vue
<script lang="ts" setup>
import { createApp } from 'vue';
import { useProvideStores, useStore } from 'pinia-di';
import { AppStore } from '@/stores/appStore';
import { TestStore } from '@/stores/testStore';
const app = createApp({
setup() {
// 'app' is the injector name that help to debug
useProvideStores([AppStore], 'app');
// after useProvideStores, you can use useStore to get the provided stores
const appStore = useStore(AppStore);
cosnt otherStore = useStore(OtherStore);
//...
}
});
app.mount('#app');
// the testStore is provided by parent injector
const testStore = useStore(TestStore);
// 'test' is the injector name that help to debug
useProvideStores([TestStore], 'test');
// testStoreNew is provided by the `useProvideStores` above
const testStoreNew = useStore(TestStore);
</script>
```

### `StoreProvider`
Expand All @@ -151,13 +150,11 @@ Use `StoreProvider` to provide stores.
import { StoreProvider } from 'pinia-di';
import { AppStore } from '@/stores/appStore';
import { TestStore } from '@/stores/testStore';
const stores = [AppStore];
</script>
<template>
<!-- // 'app' is the injector name that help to debug -->
<StoreProvider :stores="stores" name="app">
<StoreProvider :stores="[AppStore]" name="app">
<Main />
<div>
Expand Down

0 comments on commit 98f0623

Please sign in to comment.