반응형
250x250
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 | 31 |
Tags
- 콜백함수
- 인프런무료강좌
- EntityFramework
- 자바스크립트
- 자바스크립트recude
- 비주얼스튜디오
- 인프런자바스크립트
- c#
- 객체리터럴
- 자바스크립트틱택토
- HTTP
- 인프런강좌
- 고차함수
- sort
- 인프런인강
- 인프런
- slice
- 코딩
- 제로초
- 객체의비교
- 이벤트리스너
- NPM
- 자바스크립트파라미터
- .NET
- Blazor
- 틱택토구현
- 인터넷프로토콜
- 자바스크립트객체리터럴
- 자바스크립트함수
- 인프런강의
Archives
- Today
- Total
샐님은 개발중
Vuex #3 MUTATIONS 사용 본문
728x90
반응형
MUTATIONS : state 값을 변화 시킴. 변이
store.js
mutations: {
addUsers:(state,payload)=>{ //payload 가져온 값을 넘겨주는 역할
state.allUsers.push(payload)
}
signup.vue
1.mapMutations 를 import 시켜서 씀.
<script>
import { EventBus } from '@/main.js'
import { mapMutations } from 'vuex' <!--1. mapMutaitons import시킴 -->
export default {
data() {
return {
userId: null,
password: null,
name: null,
address: null,
src: null
}
},
methods: {
...mapMutations(['addUsers']) <!--2. store의 mutations에 선언된 함수 가져옴 -->
signUp() {
let userObj = {
userId: this.userId,
password: this.password,
name: this.name,
address: this.address,
src: this.src
}
/* EventBus.$emit('signUp', userObj) */
this.addUsers(userObj) <!--3.userObj 객체 즉 payload를 변수로 들고가서 함수 실행시킴 -->
this.clearForm()
},
clearForm() {
this.userId = null,
this.password = null,
this.name = null,
this.address = null,
this.src = null
}
}
}
</script>
signup.vue
2. $store.commit(함수 이름,인자)로 바로 호출 가능하다.
this.$store.commit('addUsers',userObj)
728x90
반응형
'vue > vue기초' 카테고리의 다른 글
Vue Router #1 라우터 기초 (0) | 2021.09.23 |
---|---|
Vuex #4 ACTIONS 사용 (0) | 2021.09.12 |
Vuex #1 state (0) | 2021.09.12 |
#7.vue기초 형제 컴포넌트로 데이터 전달(event bus) (0) | 2021.09.01 |
#6.vue기초 자식 ->부모 컴포넌트로 데이터 전달(. $emit) (0) | 2021.09.01 |