vue vuex data persistence

In doing vuex data storage, we are faced with the browser to refresh the page to resolve data loss data loss, how to persist following steps need

一:npm install  vuex-persistedstate 

Two: store / index.js introduced: vuex-persistedstate

Vue from Import 'VUE' 
Import from Vuex 'vuex'
// widget incorporated
Import from persistedState 'vuex-persistedstate'
Vue.use (Vuex)

Export Vuex.Store new new default ({ State: { name: "111111" }, mutations: } {, Actions: {}, modules: {}, // default storage to localStorage plugins: [
    // default localStorage
    persistedState ()

    // set following the sessionStorage
    // persistedState ({storage: window.sessionStorage})


    // set the cookie
    //persistedState({
    //  storage: {
    //    getItem: key => Cookies.get(key),
    //    setItem: (key, value) => Cookies.set(key, value, { expires: 7 }),
//    removeItem: key => Cookies.remove(key)
    //  }
  //})

 ] })

 

 

Guess you like

Origin www.cnblogs.com/zqxi/p/12461602.html