Solve the problem of vuex storing complex parameters (such as object arrays, etc.) to refresh data loss

 

I need to jump to the search results page and carry the search results after the search page gets the results

After trying several methods, I finally adopted the method of combining vuex+sessionStorage in mutations

setResultValue(state,flag){
  sessionStorage.setItem("resultValue", JSON.stringify(flag))
  state.resultValue = flag
}

in getters

getResultValue

getResultValue(state){
  state.resultValue = sessionStorage.getItem("resultValue")
  return state.resultValue
}

Get this data on the page after the jump

this.resultValue = JSON.parse(store.getters.getResultValue)

Here we can see that we use JSON.stringify and JSON.parse because sessionStorage needs to store objects, otherwise we can only get: "[object, object]" when the page is fetched

 

Guess you like

Origin blog.csdn.net/liona_koukou/article/details/83829363