Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

282
Visualizações
Get function inside default export function

I have function inside user.js with default export like this

export default {  
  var getListFriends = async (accessToken) =>{
  }
  ....other function
  return {
    getListFriends,
    ...other function...
  }
}

then I import it to index.js

import userService from './user';

Then I will add only index.js to plugin.

I can call this.$userService (it shows as anonymous function) but this.$userService.getListFriends return undefined.

How can I call function getListFriends from import. Thank you very much.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

where is user.js? if its inside plugins directory, you have to use inject to add it to your nuxt.

then you can access it via nuxt object inside your code. see this example from nuxt docs:

export default ({ app }, inject) => {
  // Inject $hello(msg) in Vue, context and store.
  inject('hello', msg => console.log(`Hello ${msg}!`))
}

you can see the full document here

about 4 years ago · Juan Pablo Isaza Relatório

0

ok now for this to work the way you want you need to change your user.js file,

export default {
  friends: () => {
    console.log('hi bro');
  },
  notFriends: () => {
    console.log('go away man im not your bro');
  }
};

something like this. you dont need inject or app in your user.js. and your code problem is that you are defining a function and trying to access it's inner values from the outside like:

function boo() {
  var b = 0;
}

you can not access the value of b with boo.b. its a local variable to the boo function

instead create a object and have multiple functions inside your object

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda