【发布时间】:2021-12-04 18:26:15
【问题描述】:
我有元素的对象,我使用 v-for 循环在页面上显示它们:
<template v-for="(item, index) in myObject">
<v-row :key="index">
<v-col>
<v-text-field
v-model="item.value"
:label="item.name"
/>
</v-col>
</v-row>
</template>
<!-- additional TextField -->
<v-row>
<v-col>
<v-text-field
v-model="modifyDateTime"
label="Modify date and time"
/>
</v-col>
</v-row>
它工作正常,但我在 v-for 块之后添加了额外的 v-text-field,它比 v-for 中的元素更早显示 循环渲染。
我该如何解决这个问题?我需要在渲染元素 v-for 循环之后立即显示最后一个 v-text-field 元素
【问题讨论】:
-
将两者都包装在
<div v-if="myObject.length"> -
@LawrenceCherone 谢谢!现在可以使用了
-
不要将索引用作
:key...尤其是与任何输入元素一起使用... -
@MichalLevý 为什么?
-
因为将
index用作key与不使用keyat all 相同
标签: javascript typescript vue.js