Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

121
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda