简体   繁体   中英

How to get query from url and send it to Store at nuxt js project

In my nuxt project I let users to download Pdf, when users clicked the link I will direct users to a new page.In here,I want to take url queries(informations) in this page and send it to store to return state informations. When I get state information i will show it in current page.

http://localhost:3000/printPdf?pdfId=690a9567-4c36-41c0-893c-587be307df25&number=1153379003428

This is my link. When user clicked it, I will take printId and number in store and i will return a state to create my pdf. I used created and Asyncdata also.

  asyncData({app, params, route, store}) {
        const url = route.query

        store.dispatch('POST_PDF_PRINT', url)
          
    }

In asyncData we can do

   asyncData({app, params, route, store}) {
               
                    //through route
                    console.log(route.params.url)
                    //through param
                    console.log(params.url)
          
            }

In the mounted method, we can access param through $route object.

 mounted() {
       //for full path
       this.$route.fullPath
       //for route param
       this.$route.params.url
      }

<p>{{ $route.query.your_key }}</p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM