亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Vue JS中如何根據(jù)數(shù)組動(dòng)態(tài)新增/刪除插槽字段
P粉639667504
P粉639667504 2023-08-28 17:43:21
0
1
622
<p>我有以下程式碼,它接受一個(gè)包含要重複的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>當(dāng)我使用<code>removeRow(index)</code>時(shí),它總是移除最後一個(gè)插槽。我已經(jīng)測(cè)試了使用<code><input v-model="row.value"></code>,正確的輸入在這裡移除了,但從未移除正確的插槽。 </p> <p>我不需要插槽中的輸入是動(dòng)態(tài)的或與Vue交互,我只是想允許用戶透過(guò)Vue組件動(dòng)態(tài)添加/刪除行。 </p> <p>請(qǐng)看我用來(lái)新增/刪除行的下面兩種方法,以防問(wèn)題出在這裡:</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

全部回覆(1)
P粉463824410

為您的 v-for 迴圈元素新增一個(gè)獨(dú)特的 key 值:

<div-for="(row, index) in rows" :key="JSON.stringify(row)">

這樣可以確保從 DOM 中正確地移除元素。

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板