Requirement : left tree and right table. After selecting a node in the organization tree, enter the details page and keep it selected when returning. Other query conditions also need to maintain state. Idea : Use vuex combined with localStorage to cache data. When a tree node or query button is clicked, the data is saved in vuex and also in localStorage. When the page rolls back, the data in localStorage is put into vuex. In the page code, it is determined whether there is data stored in vuex. If there is, it is used directly. If not, the initial data is used by default. When the page navigation route jumps, the cached page data is cleared. Code:When a tree node is clicked, the id is saved in vuex. Triggering actions through dispatch
In vuex's actions, trigger the methods in mutations by committing RemoveDeviceFaultId({ commit }) { //commit('REMOVE_DEVICEFAULTID') will be used later to clear data; }, SetDeviceManageId({ commit }, id) { commit('SET_DEVICEMANAGEID', id); }, REMOVE_DEVICEFAULTID: (state) => { state.devicFaultId = null Storage.remove('devicFaultId'); }, SET_DEVICEMANAGEID: (state, deviceManageId) => { state.deviceManageId = deviceManageId Storage.set('deviceManageId', deviceManageId); } state: Get cached data from localStorage when the page is first created devicFaultId: Storage.get('devicFaultId'), Enter a detail page and return this.params.organizeId = this.$store.state.tree.devicFaultId ? this.$store.state.tree.devicFaultId : res.data[0].id; When clicking on other routes, remember to clear the cached data this.$store.dispatch('RemoveDeviceFaultId') Replenish: After introducing it in vuex, you can use it through SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Implementation of services in docker accessing host services
>>: Summary of block-level elements, inline elements, and variable elements
Table of contents 1. Closure 2. Closure usage sce...
Table of contents Component Infrastructure Purpos...
What are the benefits of learning HTML? 1: Easily...
Table of contents question analyze solve Replace ...
Table of contents The first The second Native Js ...
Recently, I found that the company's server t...
Table of contents 1. Overview 2. Application Exam...
Preface Interceptor In some modern front-end fram...
background: I have done a project before, which r...
This article example shares the specific code of ...
Table of contents 1. Introduction to Jenkins 2. I...
Table of contents Preface 1. Introduction to one-...
After solving the form auto-fill problem discussed...
What is Load Balancing Load balancing is mainly a...
Netfilter Netfilter is a packet processing module...