Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot set property 'String' of undefined #14

Open
transtone opened this issue May 25, 2018 · 8 comments
Open

Uncaught TypeError: Cannot set property 'String' of undefined #14

transtone opened this issue May 25, 2018 · 8 comments

Comments

@transtone
Copy link

transtone commented May 25, 2018

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
@maple3142
Copy link
Owner

Can you show me ./modules/login?

@transtone
Copy link
Author

./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

@maple3142
Copy link
Owner

Is token a object? Or string?
If it is an object, it might happened when the plugin try to merge state.
See: #9 (comment)

@transtone
Copy link
Author

transtone commented May 25, 2018

token is string.

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

@maple3142
Copy link
Owner

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

@transtone transtone reopened this May 26, 2018
@transtone
Copy link
Author

transtone commented May 26, 2018

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.

@maple3142
Copy link
Owner

maple3142 commented May 26, 2018

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.

@knackjason
Copy link

knackjason commented Nov 2, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants