데이터의 흐름은 Actions -> Mutations -> State 순서임을 알 수 있습니다.
actions --(commit)--> mutations --(mutate변화)--> state --(render)--> vue components
--(dispatch)--> actions
actions: Backend API를 받는다.
vuex 구조도 : actions, mutations, state를 의미한다.
('index'.js)생성 --파일이름 자유
import Vue from 'vue';
import Vuex from 'vuex';
import {
getNotice, getNoticeContents
} from '../api/api.js'; //action역할
Vue.use(Vuex); //필수
export const store = new Vuex.Store({ //const 대신 default 사용 가능
state: {
notice: [],
noticeInfo: {},
},
mutations: {
SET_NOTICE(state, notice) {
state.notice = notice;
},
SET_NOTICE_INFO(state, noticeInfo) {
state.noticeInfo = noticeInfo;
}
},
actions: {
GET_NOTICE() {
getNotice()
.then(response => {
console.log("response");
console.log(response.data);
})
.catch();
},
GET_NOTICE_INFO(idx) {
getNoticeContents(idx)
.then(response => {
console.log(response.data);
});
}
}
})
'나의 보유기술(플랫폼) > VUE.JS' 카테고리의 다른 글
vue 프로젝트 시작! --views폴더(NoticeView.vue) (0) | 2021.01.31 |
---|---|
vue 프로젝트 시작! --routes폴더 (0) | 2021.01.31 |
vue 프로젝트 시작! --views폴더(Popup.vue) (0) | 2021.01.31 |
vue 프로젝트 시작! --api 폴더 (0) | 2021.01.31 |
vue 프로젝트 시작! --폴더추가 (0) | 2021.01.31 |