Created
October 26, 2017 14:22
-
-
Save jquerygeek/8a07ef6e259d6a0fa5628d71c3730990 to your computer and use it in GitHub Desktop.
custom store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// my-store.js | |
import Vue from 'vue' | |
import axios from 'axios' | |
export const myStore = new Vue({ | |
data: { | |
messages: [], | |
contacts: [] | |
}, | |
methods: { | |
addMessage(newMessage) { | |
this.messages.push(newMessage) | |
}, | |
getMesseges() { | |
return this.messages | |
}, | |
updateMessages(messeges) { | |
this.messages = messeges | |
}, | |
getUnreadMesseges() { | |
return this.messages.filter(function (message) { | |
return !message.viewed | |
}) | |
}, | |
getContacts() { | |
return this.contacts | |
}, | |
deleteContact(contact) { | |
this.contacts.splice(this.contacts.indexOf(contact), 1) | |
}, | |
storeContacts() { | |
return axios.get(`http://jsonplaceholder.typicode.com/users`) | |
.then(response => { | |
this.contacts = response.data | |
}) | |
.catch(e => { | |
console.log(e) | |
}) | |
} | |
} | |
}); | |
// main.js | |
import { myStore } from './my-store.js' | |
Vue.prototype.$myStore = myStore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment