Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

347
Views
Vue.js: Textarea inside v-for loop is not working

v-model value inside v-for loop is not unique.

This is my template:

   <template>
      <div
        id="FAQ"
        v-for="(question, index) in questions.slice().reverse()" 
        :key="index"
        class="m-2 col-7"
      >
          <div v-if="getloggedUser.role == 'tutor'">
            <div id="divQuestion">
              <p class="m-5">{{ question.text }}</p>
            </div>
            <div id="divAnswer" class="mt-2">
              <p class="m-2">{{ question.answer }}</p>
            </div>
          </div>
          <div v-else>
            <div id="divQuestion">
              <p class="m-5">{{ question.text }}</p>
            </div>
            <div id="divAnswer" class="mt-2">
              <p class="m-2">{{ question.answer }}</p>
            </div>
            <div v-if="question.answer == null" id="divPsycAnswer">
              <textarea cols="60" rows="3" style="border-radius:12px" v-model="answer.text"></textarea>
              <button id="btnSend" @click="publishAnswer(question.id)">Responder</button>
            </div>
          </div>
      </div> 
   </template>

This is the script (data):

  data() {
    return {
      // arrayFAQ: [],
      form: {
        text: ""
      },
      answer: {
        text: ''
      },
      questions: [],
      message: "",
      loading: false,
      id: null
    }
  },  

This way, everytime I write in one textarea, I write for all the others. I have tried adding [index] in the v-model but there's this error: "TypeError: Cannot use 'in' operator to search for '0' in "

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this as your v-model

<textarea v-model="answers[`text${index}`]"></textarea>

The answer object could be an empty object. It will give you text0, text1, text2, as answer's properties. You can add anything instead of index, like your question's id for easy access and knowing which text is from which question.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!