티스토리 뷰
mapState
- Vuex에 선언한 state 속성을 뷰 컴포넌트에 더 쉽게 연결해주는 헬퍼
//App.vue
import {mapState} from 'vuex'
computed() {
...mapState(['num'])
// num() {return this.$store.state.num}
}
//store.js
state: {
num: 10
}
<!-- <p>{{this.$store.state.num}}</p> -->
<p>{{ this.num }}</p>
mapGetters
- Vuex에 선언한 getters 속성을 뷰 컴포넌트에 더 쉽게 연결해주는 헬퍼
//App.vue
import { mapGetters } from 'vuex'
computed() { ...mapGetters(['reversMessage']) }
// store.js
getters: {
reverseMessage(state) {
return state.msg.split('').reverse().join('');
}
}
<!--<p>{{this.$store.getters.reverseMessage}}</p>-->
<p>{{this.reverseMessage}}</p>
mapMutations
- Vuex에 선언한 mutations 속성을 뷰 컴포넌트에 더 쉽게 연결해주는 헬퍼
//App.vue
import { mapMutations } from 'vuex'
methods: {
...mapMutations(['clickBtn'])
}
//store.js
mutations: {
clickBtn(state){
alert(state.msg)
}
}
<button @click="clickBtn"> popup message </button>
mapActions
- Vuex에 선언한 actions 속성을 뷰 컴포넌트에 더 쉽게 연결해주는 헬퍼
import { mapActions } from 'vuex'
methods: {
...mapActions(['delayClickBtn'])
}
//store.js
actions: {
delayClickBtn(context) {
setTimeout(() => context.commit('clickBtn'), 2000);
}
}
<button @click="delayClickBtn"> delay popup message </button>
헬퍼의 유연한 문법
- Vuex에 선언한 속성을 그대로 컴포넌트에 연결하는 문법
//배열 리터럴
...mapMutations([
'clickBtn', //'clickBtn': clickBtn
'addNumber' // addNumber(인자)
])
- Vuex에 선언한 속성을 컴포넌트의 특정 메서드에다가 연결하는 문법
//객체 리터럴
...mapMutations({
popupMsg : 'clickBtn' // 컴포넌트 메서드명 : Store의 뮤테이션 명
})
'dev > vue3' 카테고리의 다른 글
composition API에서는 왜 setup에서 .value로 접근해야 할까? (0) | 2025.01.25 |
---|---|
Composition API란 무엇인가? (0) | 2025.01.22 |
Vuex - mutations (0) | 2025.01.14 |
ES6 - Enhanced Object Literals - 향상된 객체 리터럴 (0) | 2025.01.10 |
ES6 - Arrow Function (0) | 2025.01.10 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 백엔드 개발자 공부
- ArgumentResolver
- exception
- 예외처리
- react실행
- 인터셉터
- hypertexttransferprotocol
- 컨트
- 향해플러스백엔드
- HTTP
- reject
- React
- filter
- JPA
- BindingResult
- 향해플러스
- thymleaf
- rejectValue
- 항해플러스
- SpringBoot
- Intercepter
- 백엔드 개발자 역량
- 스프링부트
- 스프링공부
- 로그인
- Java
- 항해99
- jpa api
- 향해99
- 리터럴
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함