The asyncData parameter in nuxt in nuxt, and the problem that the value of context store is empty after the page is refreshed.

functional requirements:
there is a search box on the home page and a search box on the list page. Enter the search content on the home page and jump to the search page to perform the search

.

nuxt implementation:
save the searchKeyWords field into vuex, on the home page, then go to the search page to get the searchKeyWords field, and perform a search

question:
after jumping from the home page to the search page, after the page is refreshed, the data in the searchKeyWords,store obtained through the context store turns out to be empty

.
async asyncData({ store, params }) {
            let searchParams = {
                keyword: store.state.searchKeyWords,  //searchKeyWords
                pageNo: 1,
                pageSize: 10
            }
            let { result } = await API.searchMethod(searchParams);
            return {
                searchData:resul
            }
        }

but there is data in vuex

clipboard.png

May.26,2021

when you refresh, the value of store is actually empty. You can console.log it. Sometimes plug-ins cannot be updated in real time. Take a look at the route authentication of nuxt official website. the user information to be saved by https://zh.nuxtjs.org/example. is stored in session. Then it is written to the front-end layer through the nuxtServerInit cycle. Of course, there are some problems here on the official website. The session module used in the middle layer here can only be used in the development mode, and the generation mode cannot be run. How do you solve it by using redis


?

Menu