pass specific parameter to a function pass specific parameter to a function vue.js vue.js

pass specific parameter to a function


You could pass an object rather the fixed parameters and destructure it by using ES6 Object destructuring

Example.

getBooks({ page, count, authorId }){  return API.get('/books/?page=' +page + '&count='+count+ '&author='+ authorId})    .then(response => {        return response.data    })}getBooks({ authorId: 45});getBooks({ page: 'abc', authorId: 67});


getBooks(null, null, id)

should do the trick. Note that your code won't work as page and count in your function will not be defined.


Instead of multiple arguments you can change how getBooks work and pass an object instead

getBooks({ page, count, authorId })

you can now just pass the authorId if you need

getBooks({ authorId: 'authorIdPassed' });