I want to make a function, where I am giving in 2 parameters, string, and array, and that array is equal to what I get from Axios, but I run into the problem {'assignment' is assigned a value but never used.}, but I want that the this.quizzAllCategories is equal to parameter assignment
callAPI(params: string, assignment: quizzType[]) {
axios
.get(`https://printful.com/test-quiz.php?action=${params}`)
.then((res) => {
assignment = res.data;
});
},
},
async created() {
await this.callAPI("quizzes", this.quizzAllCategories);
},
CodePudding user response:
You have to return the data from the function, not expect the "return variable" as another parameter, that's not how it works.
callAPI(params: string) {
return axios
.get(`https://printful.com/test-quiz.php?action=${params}`)
.then((res) => {
return res.data;
});
},
},
async created() {
this.quizzAllCategories = await this.callAPI("quizzes");
},
CodePudding user response:
ESLint lint behavior is right. You've declared assignment and assigned it a value, but u aren't using it in your Code anywhere.
Solution: It should disappear if use it anywhere:)
Solution 2 which is not recommended: you can disable it by adding these, before this line
// eslint-disable-next-line no-unused-vars
assignment = res.data
/* eslint-enable no-unused-vars */
