Skip to content

Instantly share code, notes, and snippets.

@sanath-kumar
Created July 19, 2018 14:26
Show Gist options
  • Select an option

  • Save sanath-kumar/174acf57d6efdf19d7dd2826cd0208fc to your computer and use it in GitHub Desktop.

Select an option

Save sanath-kumar/174acf57d6efdf19d7dd2826cd0208fc to your computer and use it in GitHub Desktop.
import Vue from 'vue'
import Vuex from 'vuex'
import Axios from 'axios'
Vue.use(Vuex);
export const store = new Vuex.Store({
state : {
chats : null,
handle : ""
},
getters : {
CHATS : state => {
return state.chats
},
HANDLE : state => {
return state.handle
}
},
mutations : {
SET_CHAT : (state,payload) => {
state.chats = payload;
},
ADD_CHAT : (state,payload) => {
state.chats.push(payload);
},
SET_HANDLE : (state,payload) => {
state.handle = payload;
}
},
actions : {
SET_CHAT : async (context,payload) => {
let {data} = await Axios.get('http://localhost:5000/chat');
console.log(data);
context.commit("SET_CHAT",data);
},
ADD_CHAT : (context,payload)=> {
context.commit("ADD_CHAT",payload);
},
SET_HANDLE : (context,payload)=> {
context.commit("SET_HANDLE",payload);
}
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment