From: istiyak Date: Wed, 9 Feb 2022 09:45:05 +0000 (+0530) Subject: docs: add increment function example X-Git-Tag: @pinia/testing@0.0.10~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5da5a1648d5a717e225fe39c78442f1cef7a05fe;p=thirdparty%2Fvuejs%2Fpinia.git docs: add increment function example --- diff --git a/packages/docs/core-concepts/index.md b/packages/docs/core-concepts/index.md index 03230718..ca702b77 100644 --- a/packages/docs/core-concepts/index.md +++ b/packages/docs/core-concepts/index.md @@ -92,10 +92,41 @@ export default defineComponent({ :::warning Extracting `actions` using `storeToRefs` will result in `actions` being `undefined`. To extract `actions` from the store, you should skip using `storeToRefs` -``` -const store = useStore() +```js +import { storeToRefs } from 'pinia' +import useCounterStore from '@/store/counter' + +export default defineComponent({ + const store = useCounterStore() + + const { counter, increment } = storeToRefs(store) + + counter // 1 + + // ❌ This won't work because + // `storeToRefs` skips `actions` from the store + increment() // "undefined" + -const { fullName, age } = store -const { logIn } = store + // if you want to only destructure `actions` + // from the store then don't use `storeToRefs` + const { increment } = store + + increment() // works! + counter // 2 +}) ``` ::: + +:::tip +- **To extract only the properties from the store:** + - `const { counter } = counterStore` + +
+ +- **To extract only the actions from the store:** + - `const { increment, decrement } = counterStore` +::: + + +