我想将功能renderAnswers()
分配给POST中的问题。如何正确地工作。那应该可以完成我的工作吗?
methods: {
renderAnswers() {
let answers = this.question;
let newAnswers = answers.map((isAnswer) => ({
answers: isAnswer,
}))
console.log(newAnswers);
},
async createQuiz(quiz, question) {
try {
let add = await axios.post("http://localhost:3000/v1/quiz/" , {
name: quiz.name,
type: question.type,
question: this.renderAnswers(),
});
router.push({path: '/listQuizzesInstructor'});
} catch(e) {
this.errors.push(e);
}
}
答案 0 :(得分:0)
您需要从renderAnswers
返回一个值。
methods: {
// add a return statement
renderAnswers() {
return this.question.map((isAnswer) => ({ answers: isAnswer }))
},
async createQuiz(quiz, question) {
try {
let add = await axios.post("http://localhost:3000/v1/quiz/" , {
name: quiz.name,
type: question.type,
question: this.renderAnswers(),
});
router.push({path: '/listQuizzesInstructor'});
} catch(e) {
this.errors.push(e);
}
}