Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

339
Views
get updated query in nuxt plugin after page load

Well, I have a plugin with some functions in it, functions should update URL queries. The problem is, everytime I execute $global.changePage(2) or $global.changeLimit(2) the console.log(query) returns an empty object and didn't return updated queries in URL.

I know NuxtJS plugins execute once we load the page but is there any way to have updated query each time I use those functions?

export default (ctx: NuxtConfig, inject: Inject) => {
  const { app, query } = ctx;

  const global = {
    changePage (page: number) {
      console.log(query);
      
      app.router.push({
        query: { ...query, page }
      })
    },

    changeLimit(limit: number) {
      console.log(query);

      app.router.push({
        query: { ...query, limit }
      })
    },
  }

  inject('global', global)
  ctx.$global = global
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simply remove ctx.$global = global from the last line of your plugin.

The inject method provided by Nuxt takes care of making your global object available where it's needed, so there's really no need for you to overwrite the ctx.$global property.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!