Preface In the form filter items in the project, after selecting, the data will change when the page is refreshed, and it will not be retained on the option you selected. Tip: The following is the main content of this article. The following cases can be used for reference 1. Reasons:Vuex is a global data state management mechanism. The data in the store is stored in the running memory. When the page is refreshed, the page will reload the Vue instance, and the data in the store will be reassigned to the initialized state. 2. Solution ideas:Use vuex with local storage to refresh the page without losing data 1. Local storage method:
Extension: Cookie application scenarios (1) Determine whether the user has logged in to the website so that the user can log in automatically (or remember the password) the next time. If we delete cookies, you must fill in the login information again every time you log in. 2. Implementation steps:Since vue is a single-page application, all operations are completed on one page, and this project is only used in the currently opened project, so it is more appropriate to use sessionStorage
//store/selectData.js const state = {//data stored in state dataList: { exchangeIdSum: null, } } const mutations = { setExchangeIdSum(state, data) { //Reassign the selected data and save it to sessionStorage state.dataList.exchangeIdSum = data sessionStorage.setItem('dataList',JSON.stringify(state.dataList)) } setDataList(state, data) { state.dataList = JSON.parse(JSON.stringify(data)) } } const actions = { resetDataList: ({commit}, list) => { setTimeout(() => { commit('setDataList', list) }, 2000); } } export default { state, mutations, actions, } //Operation methods in the form filtering page: { exchangeChange(val) {//Modify the data in state when the drop-down box is selected this.$store.commit('selectData/setExchangeIdSum', val) }, } //App.vue in create(){//As soon as the page is entered, determine whether there is data in sessionStorage sessionStorage.getItem('dataList')? this.$store.dispatch('selectData/resetDataList', JSON.parse(sessionStorage.getItem('dataList'))):{} } 3. Optimization: Because when modifying state data before, each mutation must modify sessionStorage, but if there is a lot of state data to be modified, sessionStorage will be modified every time, which is a bit troublesome. solve: This concludes this article about how to use vuex combined with session storage data to solve the problem of data loss when refreshing a page. For more relevant vuex session storage data content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Use Nginx to build a streaming media server to realize live broadcast function
>>: A brief introduction to MySQL storage engine
This article is mysql database Question 1 Import ...
After installing a centos8 service under vmware a...
MySQL consistency log What happens to uncommitted...
The reason for writing this article is that I wan...
background When working on the blockchain log mod...
Copy code The code is as follows: <a href=# ti...
1. Download the tomcat compressed package from th...
I am planning to build my own website, so I took ...
Preface Query optimization is not something that ...
This article shares the specific code of js to ac...
In a table, you can define the color of the lower...
Table of contents Basic application of javascript...
Preface Most people will probably perform this op...
This article uses examples to illustrate the prin...
1. Introduction to yum Yum (full name Yellow dogU...