-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff5b0ab
commit 4a881b8
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,7 @@ module.exports = { | |
children: [ | ||
'/pinia/intro', | ||
'/pinia/store', | ||
'/pinia/state', | ||
], | ||
}, | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
title: State 🆕 | ||
--- | ||
|
||
# State | ||
|
||
상태(state)는 여러 컴포넌트에서 공유되는 데이터(data 속성)를 의미합니다. | ||
|
||
## state 선언 | ||
|
||
피니아 스토어 안에서 다음과 같이 화살표 함수 형태로 정의합니다. | ||
|
||
```js | ||
export const useStore = defineStore('app', { | ||
state: () => { | ||
return { | ||
count: 0 | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
## state 접근 | ||
|
||
컴포넌트의 setup() 함수 안에서 반환한 값으로 상태를 접근합니다. | ||
|
||
<code-group> | ||
<code-block title="Vue 3"> | ||
```js | ||
export default defineComponent({ | ||
setup() { | ||
const store = useStore(); | ||
return { store }; | ||
} | ||
}); | ||
``` | ||
</code-block> | ||
|
||
<code-block title="Vue 2"> | ||
```js | ||
export default { | ||
setup() { | ||
const store = useStore(); | ||
return { store }; | ||
} | ||
}; | ||
``` | ||
</code-block> | ||
</code-group> | ||
|
||
|
||
```html | ||
<template> | ||
<p>{{ store.count }}</p> | ||
</template> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters