小编Lev*_*mes的帖子

Vue.js - 使用 v-for 和动态范围值

也许我正在以错误的方式处理这个问题......但我正在尝试使用循环v-for来复制/删除自定义组件x时间。x由上面的字段决定<select>。我所拥有的适用于初始页面加载,但是当您选择不同的选项时,仅显示一个自定义组件(尽管x已更新)。有谁知道我做错了什么?

// here is the select field that defines the number of enrolling students
<select name="number_students_enrolling" v-model="formFields.numberStudentsEnrolling">
    <option value="" default selected></option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
</select>

// here is the custom component I'm trying to duplicate/remove dynamically
<div class="students-container">
    <student v-for="n in formFields.numberStudentsEnrolling" :key="n" v-bind:index="n" >
    </student>
</div>

// here is the custom component
Vue.component('student', {
  props: ["index"],
  template: `
    <div class="input--student">
      <div class="input--half">
        <label>
          <span class="d-block">
            Student …
Run Code Online (Sandbox Code Playgroud)

vue.js

4
推荐指数
1
解决办法
1616
查看次数

标签 统计

vue.js ×1