11.29 Notes
vuex and localStorage difference
-
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.
-
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 )
-
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.
Refresh your browser fallback:
- Add a hiddeninput Tab, setvalue=“no”
<input type="hidden" id="refreshed" value="no">
- 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()
}
}