added axios, datarest, vuex

This commit is contained in:
2019-04-02 12:59:58 +02:00
parent 1017ecdc95
commit 8dd21b9e2d
11 changed files with 177 additions and 21 deletions
+17
View File
@@ -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()] : []
})
+48
View File
@@ -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
}