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

336
Views
Vuejs: get parameters from url in js file?

I have a url : http://local-pr.local?id=12

In page.vue :

  • I use : console.log(this.$route.query.id) and get it successfully.

And now I want to get that params in the file : page.js

import addon from './addon'
import user from './user'

// I want to check if there is a new params id that has it export default
if (this.$route.query.id) {
   export default [...addon, ...user]
}
  • console.log(this.$route.query.id)

ERROR: Reason: TypeError: Cannot read properties of undefined (reading '$route')

Is there any way to get params in js file? Please give me some experience. Thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could export a function that takes the $route as parameter :


import addon from './addon'
import user from './user'

export default function  checkParams(route) {
   if(this.$route.query.id){
    return [...addon, ...user]
  }
}

and in any component you could do :

import checkParams from './page.js'

.....

let data=checkParams(this.$route)

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!