Vue JS中如何根据数组动态添加/删除插槽字段
P粉639667504
P粉639667504 2023-08-28 17:43:21
0
1
341
<p>我有以下代码,它接受一个包含要重复的HTML字段的插槽:</p> <pre class="brush:php;toolbar:false;"><div v-for="(row, index) in rows" :key="index"> <div class="d-flex justify-content-between "> <slot name="fields"> </slot> <input v-model="row.value" /> <button @click="removeRow(index)" type="button" class="btn btn-primary waves-effect waves-float waves-light height-10-per " > Remove <i class="fa fa-times-circle"></i> </button> </div> </div></pre> <p>当我使用<code>removeRow(index)</code>时,它总是移除最后一个插槽。我已经测试了使用<code><input v-model="row.value"></code>,正确的输入在这里被移除了,但从未移除正确的插槽。</p> <p>我不需要插槽中的输入是动态的或与Vue交互,我只是想允许用户通过Vue组件动态添加/删除行。</p> <p>请查看我用于添加/删除行的下面两种方法,以防问题出在这里:</p> <pre class="brush:php;toolbar:false;">removeRow(index){ this.rows.splice(index, 1); }, addRow(){ this.rows.push({value: 'test'}) }</pre> <p>非常感谢任何帮助。</p>
P粉639667504
P粉639667504

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!