Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- style
- fetch
- svelte
- NextJS13
- InteliJ
- nodejs
- 오라클
- loguru
- Java
- sveltekit
- d3js
- ubuntu
- Vue
- EUREKA
- JUnit
- springboot
- fastapi
- Python
- Logging
- gradle
- npm
- Test
- Vue3
- vitejs
- Shell
- Spring
- react
- NextJS
- vuex
- post
Archives
- Today
- Total
양군의 행복한 이야기
vue 3 + vuex 4 본문
Vuex
- vuex가 v4로 업데이트 하면서 사용법이 변경되었다.
목차
설치
vue create 프로젝트_이름
Manually select features <-- 선택
Babel, Router, Vuex <- 선택
3.x <-- 선택
Use history mode for router? (Requires proper server setup for index fallback in production)(Y/n) <- Y
In package.json <- 선택
Save this as a preset for future projects? (y/N) <- N
위의 순서대로 프로젝트를 vue cli를 사용하여 셋팅한다.
사용
store/index.js 파일 생성
import { createStore } from 'vuex' export default createStore({ state: { }, getters: { }, mutations: { }, actions: { }, modules: { } })
main.js 수정
import store from '@/store/index.js' <- 추가 createApp(App).use(store).mount('#app') <-- use(store) 추가
사용
// store import import { useStore } from 'vuex' // store 선언 const store = useStore(); const loginAction = ()=>{ store.dispatch('actons_name', {a:'aaa', b:'bbb'}); };
console.log('stat 접근 :', store.state.xxxxxx);
console.log('getter 접근 :', store.getters.xxxxxx);
const computed_sample = computed(()=>store.getters.xxxxxx);
// watch sample
watch(computed_sample, (newValue, beforValue) =>{console.log("watching sample : ", computed_sample.value)});
```