Currently, I have a URL: http://local-pr.local?id=12
Within the file page.vue:
- Upon using:
, I successfully retrieve the value.console.log(this.$route.query.id)
Now, my objective is to access this parameter in the file: page.js
import addon from './addon'
import user from './user'
// My intention is to verify if there is a new 'id' parameter that needs to be exported.
if (this.$route.query.id) {
export default [...addon, ...user]
}
console.log(this.$route.query.id)
However, an ERROR occurs: Reason: TypeError: Cannot read properties of undefined (reading '$route')
I am seeking guidance on how to retrieve parameters in a JavaScript file. Any insights or experiences would be greatly appreciated. Thank you!