[Vuejs]-How to update a key of an object of an array element using v-model?

0👍

One option would be to make the response part of each question, rather than using a separate array. The expansion of format creates a new response object for each question:

data: () => ({
  questions: [
    {
      text: "Question 1",
      answerType: "text",
      details: "Question 1 details",
      response: { ...format },
    },
    {
      text: "Question 2",
      answerType: "scq",
      options: ["a", "b"],
      details: "Question 1 details",
      response: { ...format },
    },
    {
      text: "Question 3",
      answerType: "mcq",
      options: ["aa", "bb"],
      details: "Question 1 details",
      response: { ...format },
    },
  ],
}),

In the HTML template, use v-model = "question.response.answer"

Leave a comment