vuex and localStorage difference

vuex and localStorage difference

  1. The most important difference: vuex data is stored in memory, refresh the page will be lost; and localstorage is stored locally on the computer, refresh and will not be lost; sessionStorage survival during the application session.

  2. Application scenarios: vuex used to pass values ​​between components (response type), localstorage are mainly used by value (other page updates data between different pages, current page to refresh to update the corresponding non-response style )

  3. Permanent: vuex global variable storage, refresh the page when the stored value vuex be lost (in the presence of memory, refresh, of course, be lost), localstorage not.

  4. I think there speak in more detail.

Refresh your browser fallback:

  1. Add a hiddeninput Tab, setvalue=“no”
<input type="hidden" id="refreshed" value="no">
  1. The first page load time executionrefreshedId.value = ‘yes’Then at load timerefreshedId.value = ‘no’And then reload again.
onload = function () {
  var refreshedId = document.getElementById('refreshed')
  if (refreshedId.value === 'no') {
    refreshedId.value = 'yes'
  } else {
    refreshedId.value = 'no'
    location.reload()
  }
}

After changing the configuration file RestartTo take effect!

Published 50 original articles · won praise 23 · views 1226

Guess you like

Origin blog.csdn.net/qq_44698161/article/details/103304257