Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Vue from 'vue'
- import Vuex from 'vuex'
- Vue.use(Vuex)
- export default new Vuex.Store({
- state: {
- pins: [],
- },
- getters: {
- getPins: state => state.pins
- },
- actions: {
- addPin(context, pin) {
- context.commit('addPin', pin);
- },
- removePin(context, index) {
- context.commit('removePin', index);
- },
- replacePins(context, pins) {
- context.commit('replacePins', pins);
- },
- },
- mutations: {
- addPin(state, pin) {
- state.pins.push(pin)
- localStorage.pins = JSON.stringify(state.pins)
- },
- removePin(state, index) {
- state.pins.splice(index, 1)
- localStorage.pins = JSON.stringify(state.pins)
- },
- replacePins(state, pins) {
- state.pins = pins
- localStorage.pins = JSON.stringify(state.pins)
- },
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement