1👍
✅
Refactor fetchReport
‘s arguments:
Instead of taking a series of arguments (arg1, arg2, arg3)
, take a single parameter (arg)
This arg
parameter will be an object including all the properties you need as arguments. As a followup, move the default values inside the function.
Result for you would be:
fetchReport(myParams) {
const defaults = { itemType: '3', locationID: '10', .... }; // list all other defaults, same as previous arguments
const params = Object.assign(defaults, myParams);
axios.get('/report/assets/data', { params })
.then(response => {
// handle success
console.log(response.data)
this.rows = response.data
})
},
Then, when you need to call fetchReport:
fetchReport({ itemType: 'MyValue' })
fetchReport({ locationID: 'MyValue' })
This is the best practice way of handling functions with multiple parameters when you don’t want to think about order of parameters
0👍
Use undefined to pass the first parameter.
handleLocationSelect() {
this.fetchReport(undefined, itemLocations.value);
}
0👍
Source:stackexchange.com