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

122
Views
Using store and route in a third-party script (nuxt ^2.15.3)

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

about 4 years ago · Juan Pablo Isaza
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!