SHARE
TWEET

Store.js - Step 4.2.4

dwadedev Mar 15th, 2019 (edited) 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import { db } from '@/main'
  4.  
  5. Vue.use(Vuex)
  6.  
  7. export default new Vuex.Store({
  8.   state: {
  9.     items: null
  10.   },
  11.   getters: {
  12.     getItems: state => {
  13.       return state.items
  14.     }
  15.   },
  16.   mutations: {
  17.     setItems: state => {
  18.       let items = []
  19.  
  20.       db.collection('items').orderBy('created_at').onSnapshot((snapshot) => {
  21.         items = []
  22.         snapshot.forEach((doc) => {
  23.           items.push({ id: doc.id, title: doc.data().title })
  24.         })
  25.  
  26.         state.items = items
  27.       })
  28.     }
  29.   },
  30.   actions: {
  31.     setItems: context => {
  32.       context.commit('setItems')
  33.     }
  34.   }
  35. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top