search

Home  >  Q&A  >  body text

Create input labels as length of v-model

<p><pre class="brush:php;toolbar:false;"><div v-if="quesType === 'Çoktan Seçmeli'" class="row p-3 bg-dark text-light"> <div class="col-4"> <select v-model="coktanSecmeli" class="form-select" name="" id=""> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> </select> </div> <div v-for="item in coktanSecmeli"> <input type="text"/> </div> </div> export default defineComponent({ name: "SoruEkle", data() { const quesType = ""; const coktanSecmeli = 0; return { quesType, coktanSecmeli, }; }, components: { ErrorMessage, Field, Form, }, props: { widgetClasses: String, }, methods: {}, });</pre> <p>我尝试过,但无法解决这个问题。我如何获取 v-model 的长度并使用该长度创建 html 标签作为该模型的长度。我也尝试过使用 array 和 v-html 但没有成功。</p>
P粉916553895P粉916553895467 days ago468

reply all(1)I'll reply

  • P粉190883225

    P粉1908832252023-09-03 20:18:13

    You must create a scope for coktanSecmeli. Let's define a computed property for this:

    range() {
      return [...Array(this.coktanSecmeli).keys()];
    }

    Or use standard syntax:

    range() {
      return Array.from(Array(this.coktanSecmeli).keys());
    }

    Then you should use this range for v-for:

    <div v-for="key in range">
      <input type="text" :key="key"/>
    </div>

    reply
    0
  • Cancelreply