So, here's the issue - I have a plugin containing some functions that are supposed to update URL queries. However, every time I run $global.changePage(2)
or $global.changeLimit(2)
, the console.log(query)
outputs an empty object and doesn't show the updated queries in the URL.
I'm aware that NuxtJS plugins run once the page is loaded, but is there any way to have the query updated each time these functions are used?
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
}