Slide 36
Slide 36 text
Action で Backbone.Model の処理理を使う
export default new Vuex.Store({
state: {
model: null
},
•••
mutations: {
[MUTATIONS.setModel](state, {model}) {
state.model = model;
},
[MUTATIONS.clearModel](state) {
state.model = null;
}
},
actions: {
[ACTIONS.SAVE_MODEL]: ({commit, dispatch, state}, {title, color}) => {
state.model.save({title, color}); // PUT /models/:id が実⾏行行される
},
[ACTIONS.DELETE_MODEL]: ({commit, dispatch, state}) => {
state.model.destroy({ // DELTE /models/:id が実⾏行行される
success: () => commit(MUTATIONS.clearModel)
});
}
}