vuejs-storage icon indicating copy to clipboard operation
vuejs-storage copied to clipboard

Uncaught TypeError: Cannot set property 'String' of undefined

Open transtone opened this issue 6 years ago • 8 comments

2.4.0 has this bug. 2.3.3 is ok.

image

my store/index.ts file

import Vue from "vue"
import Vuex from "vuex"
import vuejsStorage from "vuejs-storage"

const getters: any = require("./getters")
import login from "./modules/login"

Vue.use(Vuex)

const store = new Vuex.Store({
  getters,
  modules: {
    login
  },
  plugins: [
    vuejsStorage({
      keys: ["login"],
      namespace: "planx"
    })
  ]
})

export default store

transtone avatar May 25 '18 13:05 transtone

Can you show me ./modules/login?

maple3142 avatar May 25 '18 13:05 maple3142

./modules/login

import * as actions from "./actions"

const state = {
  token: null,
  user: {},
  userinfo: {}
}
const mutations = {
  setToken(state, token) {
    state.token = token
  },

  setUser(state, user) {
    state.user = user
  },

  setUserInfo(state, userinfo) {
    state.userinfo = userinfo
  },

  clearData(state) {
    state.token = null
    state.user = {}
    state.userinfo = {}
  }
}

export default {
  state,
  actions,
  mutations
}

actions is empty

transtone avatar May 25 '18 13:05 transtone

Is token a object? Or string? If it is an object, it might happened when the plugin try to merge state. See: https://github.com/maple3142/vuejs-storage/issues/9#issuecomment-389123728

maple3142 avatar May 25 '18 13:05 maple3142

token is string.

I set token = "" replace null, It works.

transtone avatar May 25 '18 13:05 transtone

I cannot reproduce the bug. https://jsfiddle.net/vc7qt2ov/ Did you add anything to an object with key String elsewhere?

maple3142 avatar May 25 '18 14:05 maple3142

I use vuejs-storage with vuex plugin vuex-orm.

I create a repo try to reproduce the bug, but failed. https://github.com/transtone/vuejs-storage-debug

I don't have time to test this, get back to 2.3.3.

transtone avatar May 26 '18 02:05 transtone

Does it works without vuex-orm? The main changes between 2.4.0 and 2.3.3 is builtin merge function can handle deep merge.

maple3142 avatar May 26 '18 05:05 maple3142

I ran into a similar problem today. In my store's state, I had user: null. This gets set to an Object after the user logs in. Everything worked fine initially. When I tried to refresh the page after logging in, however, I was told that e is null (this is after it's gone through Webpack). Everything started working once I changed user: null to user: {} in my store's state.

knackjason avatar Nov 02 '18 21:11 knackjason