project on nuxt ^2.15.3. I have a class that performs asynchronous queries to the database, I need to import the store and route so that I can use them inside, now when I initialize the class in the constructor, I assign myself a router and a store, but the problem is that when making requests on different pages, the router parameter not dynamic, it does not change ,yes i can transfer store and router from asyncData ,but it is the independent use that is of interest without the constant transfer of the store and the router.
requestMongo.js
export default class {
constructor({ store, $axios, i18n, $config, route }) {
this.api = $axios.create({
baseURL: `${$config.baseURL}/${$config.mongoURL}`,
method: 'post', // default
headers: {
common: {
Accept: "application/json",
}
}
});
this.store = store;
this.i18n = i18n;
this.route = route; - the router is static and does not show changes when you navigate to other pages
}
function.js
export default async function ({ store, $axios , i18n , route, $config }, inject) {
const requestMongo = new RequestMongo({ store,$axios,i18n,route,$config });
inject('requestMongo', requestMongo);}
nuxt.config.js
plugins: [
{ src: '@/plugins/functions.js' },]
I tried to import the store but
import store from '../../store'
or
import {store} from '../../store'
But store is undefined
is it possible to call the actual store and router in the class without resorting to
async asyncData({$requestMongo,route,$store}) {
return await $requestMongo.getSingleSlugPage({route,$store})
},
thanks for your time