added axios, datarest, vuex
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import posts from './modules/posts'
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
// https://github.com/vuejs/vuex/tree/dev/examples/shopping-cart
|
||||
|
||||
// const debug = process.env.NODE_ENV !== 'production'
|
||||
|
||||
export default new Vuex.Store({
|
||||
modules: {
|
||||
posts
|
||||
}
|
||||
// strict: debug,
|
||||
// plugins: debug ? [createLogger()] : []
|
||||
})
|
||||
@@ -0,0 +1,48 @@
|
||||
import datarest from '../../api/datarest'
|
||||
|
||||
// initial state
|
||||
const state = {
|
||||
all: [],
|
||||
opened: null
|
||||
}
|
||||
|
||||
// getters
|
||||
const getters = {}
|
||||
|
||||
// actions
|
||||
const actions = {
|
||||
getAllPosts ({ commit }) {
|
||||
datarest.getPosts(posts => {
|
||||
commit('setPosts', posts)
|
||||
})
|
||||
},
|
||||
openPost ({ commit }, post) {
|
||||
datarest.getPost(post.id, post => {
|
||||
commit('setOpened', post)
|
||||
})
|
||||
},
|
||||
closePost ({ commit }) {
|
||||
commit('clearOpened')
|
||||
}
|
||||
}
|
||||
|
||||
// mutations
|
||||
const mutations = {
|
||||
setPosts (state, posts) {
|
||||
state.all = posts
|
||||
},
|
||||
setOpened (state, post) {
|
||||
state.opened = post
|
||||
},
|
||||
clearOpened (state) {
|
||||
state.opened = null
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
}
|
||||
Reference in New Issue
Block a user