HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
💌
JJong’s Archive
/
🏞️
Vue
/
Pinia

Pinia

Select
Dec 3, 2023
vue 상태 ㄹㅏ이브러리의 기본! (Vuex5에서도 Pinia를 쓸 것임)
 
  • vuex와의 차이점
      1. createPinia로 pinia를 생성하고 최상위 컴포넌트의 모듈로 넣어줌. & 정의는 state마다 따로 definePinia로.
          • vuex: createStore로 바로 정의 및 생성 후 최상위 컴포넌트에 모듈로 넣어줌
      1. mutation이 x ⇒ actions으로 통합
      1. module이 x ⇒ 대신에 definePinia의 첫번째 인수로 상태 이름 정의
      1. actions에서 this 키워드로 바로 state, getters 등에 접근 가능(ex. this.상태데이터)
          • vuex: context.state.상태데이터
 
  1. pinia를 일반 의존성으로 설치
 
  1. createPinia로 생성 후 use로 플러그인 등록!
    1. createApp(App).use(createPinia()).mount('#app')
 
  1. defineStore로 피니아 정의
    1. import { defineStore } from 'pinia' export const useCountStore = defineStore('count', { state() { return { count: 1 } }, getters: { double(state) { return state.count*2 } }, actions: { increase() { this.count += 1 }, decrease() { this.count -= 1 } } })
       
  1. vue 컴포넌트 파일에서 정의한 store를 바로 import한 후, 변수로 등록해서 사용
    1. <script setup lang="ts"> import { useCountStore } from './store/count' const countStore = useCountStore() </script> <template> <h1>{{ countStore.count }}</h1> <h2>{{ countStore.double }} </h2> <button @click="countStore.increase">Increase</button> <button @click="countStore.increase">Increase</button> </template>
 
  • store.$reset() ⇒ 스토어의 전체 상태값 초기화
    •  

 
  • https://transform.tools/json-to-typescript
    • ⇒ json을 타입스크립트 interface 형태로 변환해주는 사이트
       
 
https://omdbapi.com/?apikey=7035c60c&s=${영화이름}