-
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
6dec6cf
commit b68b30f
Showing
2 changed files
with
74 additions
and
1 deletion.
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
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,66 @@ | ||
--- | ||
title: Introduction ๐ | ||
--- | ||
|
||
# Pinia๋? | ||
|
||
ํผ๋์(Pinia)๋ Compositoin API ๊ธฐ๋ฐ์์ ์ฌ์ฉํ ์ ์๋ ์ํ ๊ด๋ฆฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์๋ฏธํฉ๋๋ค. Vuex์ ์ต์ ๋ฒ์ ์ธ 5๋ฅผ ์๋ฏธํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ด๊ธฐ๋ ํฉ๋๋ค. | ||
|
||
## Vuex๋ ๋ญ๊ฐ ๋ค๋ฅผ๊น? | ||
|
||
[๋ทฐ์์ค(Vuex)](/vuex/concept)๋ Vue.js์ ์ํ ๊ด๋ฆฌ ํจํด์ด์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์๋ฏธํฉ๋๋ค. ๋ทฐ์์ค๊ฐ state, getters, mutations, actions๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ํ๋ฅผ ๋ค๋ค๋ค๋ฉด ํผ๋์๋ state, getters, actions๋ก ์ํ๋ฅผ ๊ด๋ฆฌํฉ๋๋ค. ๊ทธ๋์ ๋ทฐ์์ค์ ๋ค์ ๋ณต์กํ๊ฒ ๋ณด์ธ ๋ฌธ๋ฒ๋ค์ด ๋จ์ํด ์ง๋ ํจ๊ณผ๊ฐ ์์ต๋๋ค. | ||
|
||
ํ์ง๋ง ์ฅ์ ๋ง ์์ง๋ ์์ต๋๋ค. ํผ๋์๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด ์ปดํฌ์ง์ API ๊ธฐ๋ฐ ํ๋ก์ ํธ๋ฅผ ์ฌ์ฉํด์ผ ํ๋ฉฐ ๋ทฐ์์ค๊ฐ ์๋ ๋ค๋ฅธ ์ํ ๊ด๋ฆฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ๋ฒ์ ์ตํ์ผ ํ๋ ๋ฒ๊ฑฐ๋ก์์ด ์์ต๋๋ค. ๋ฐ๋ผ์, ํ๋ก์ ํธ ์ฑ๊ฒฉ์ ๋ง๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ์ถ์ฒํฉ๋๋ค. | ||
|
||
:::tip | ||
๐ ์ด๋ฏธ ์ด์ ์ค์ธ Vue 2,3 ํ๋ก์ ํธ๋ Vuex v4.x๋ฅผ ์ฌ์ฉ <br> | ||
๐ ์ ๊ท ํ๋ก์ ํธ ์ค **Composition API๋ง** ์ฌ์ฉํ๋ ํ๋ก์ ํธ๋ Pinia๋ฅผ ์ฌ์ฉ | ||
::: | ||
|
||
## Pinia ์ค์น | ||
|
||
ํผ๋์๋ ์์ ์ค๋ช ํ ๊ฒ์ฒ๋ผ Composition API๋ก๋ง ์์ฑ๋ ํ๋ก์ ํธ์์ ์ฌ์ฉํ ์ ์์ต๋๋ค. Vue 2์์ ์ฌ์ฉํ๋ ค๋ฉด [Composition API ํ๋ฌ๊ทธ์ธ](https://github.com/vuejs/composition-api)์ ๋ณ๋๋ก ์ค์นํด์ผ ํ๊ณ , Vue 3์์๋ ์ปดํฌ์ง์ API ์คํ์ผ ์ฝ๋๋ง ์์ฑํด์ผ ํฉ๋๋ค. | ||
|
||
์ปดํฌ์ง์ API๋ฅผ ์ฌ์ฉํ๋ ๋ทฐ ํ๋ก์ ํธ์์ ์๋ ๋ช ๋ น์ด๋ก ํผ๋์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ค์นํฉ๋๋ค. | ||
|
||
```sh | ||
# npm | ||
npm install pinia | ||
# yarn | ||
yarn add pinia | ||
``` | ||
|
||
## Pinia ๊ธฐ๋ณธ | ||
|
||
ํผ๋์๋ฅผ ์ ํ๋ฆฌ์ผ์ด์ ์์ ์ฌ์ฉํ๊ธฐ ์ํด์๋ main.js ํ์ผ์ ๋ค์ ์ฝ๋๋ฅผ ์ถ๊ฐํด์ผ ํฉ๋๋ค. | ||
|
||
<code-group> | ||
<code-block title="Vue 2"> | ||
```js | ||
// main.js | ||
import Vue from 'vue' | ||
import { createPinia, PiniaVuePlugin } from 'pinia' | ||
import App from './App.vue' | ||
|
||
Vue.use(PiniaVuePlugin) | ||
const pinia = createPinia() | ||
|
||
new Vue({ | ||
render: h => h(App), | ||
pinia, | ||
}).$mount('#app'); | ||
``` | ||
</code-block> | ||
|
||
<code-block title="Vue 3"> | ||
```js | ||
// main.js | ||
import { createApp } from 'vue' | ||
import { createPinia } from 'pinia' | ||
import App from './App.vue' | ||
|
||
const pinia = createPinia() | ||
createApp(App).use(pinia).mount('#app') | ||
``` | ||
</code-block> | ||
</code-group> |