如何在POST中分配问题功能?

时间:2018-12-15 18:24:10

标签: javascript vue.js vuejs2

我想将功能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);
      }
}

1 个答案:

答案 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);
      }
}