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

291
Views
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 answers
Answer question

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 Report

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 Report
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!