Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
12
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

Vue-CLI3、Vuexでリロードに耐える

vuex-persistedstateをインストール

コレをインストールします。
https://www.npmjs.com/package/vuex-persistedstate

$ npm install --save-dev vuex-persistedstate

store.jsに読み込んで使う

store.jsの末尾に追加する

store.js
import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate" //←読み込む
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    test:[],
  },
  getters:{
  },
  mutations: {
    updateStoreTest: function(state, payload){
      var self = this;
      self.state.test = payload;
    },
  },
  actions: {
    updateTest: function(dispatch, val ){
      var self = this;
      self.commit('updateStoreTest',val )
    },
  },
  plugins: [createPersistedState({storage: window.sessionStorage})] // ← ココ!
});

これでブラウザをリロードしても消えなくなります。

消し方

Session Strageは、キャッシュよりも強く残ってしまうので、
データの消し方がわからなくなると困るので、追記します。

■chromeの場合
>その他のツール
 >デベロッパーツール
  >Application
   >Session Strage
    >(あなたのドメイン)
     >vuex を×ボタンで消す

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
12
Help us understand the problem. What are the problem?