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

The data in localstorage.js file cannot be stored synchronously with localStorage #13

Open
ann61wang opened this issue Sep 14, 2019 · 0 comments

Comments

@ann61wang
Copy link

I use an object to store the data I need to cache. When an input box loses focus, the corresponding method is triggered over time to save the data in localstorage.js. Is a set of lists, when pressing the enter key, data can be synchronized, when only lose focus, localstorage.js data has changed, but not synchronized to localStorage.

localStorage.js

export const state = () => ({
  listNum: [],
  listContent: {},
  test: {
    imgAlt: '',
    imgSrc: '',
    titleCache: '',
    descCache: ''
  },
})

export const mutations = {
  changeImgAlt(state, inputValue) {
    state.test.imgAlt = inputValue
  },
  insertImg(state, obj) {
    state.test.imgAlt = obj.imgAlt
    state.test.imgSrc = obj.imgSrc
  },
  clearImgAlt(state) {
    state.test.imgAlt = ''
    state.test.imgSrc = ''
  },
  syncValue(state, value) {
    state.test.titleCache = value.title
    state.test.descCache = value.desc
  },
  syncList(state, items) {
    state.listNum = items
  },
  syncContent(state, contentObj) {
    state.listContent[contentObj.id] = contentObj.content
  },
  clearContent(state) {
    state.listContent = {}
  }
}

Method over time when the focus is lost:

handleInputBlur(e) {
     this.content = e.target.innerText
     this.syncContent(this.contentObj)
     console.log(localStorage.localStorage)
     console.log(this.listContent)
   }

Snip20190914_6

Snip20190914_5

I don't understand why this is happening. I think it's the plugin itself

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

1 participant