Transition-group children must be keyed...but they are keyed(过渡组的孩子必须有钥匙……但他们有钥匙)
问题描述
尝试在我的组件模板中使用 <animation-group>
,但出现错误:
Trying to use <animation-group>
in my component template, but getting error:
[Vue 警告]:<transition-group>子项必须键入:<div>
但我很确定它们是有键的.
But I'm pretty sure that they are keyed.
//js
Vue.component('instruments', {
template: `
<transition-group name="fade">
<div class="instruments">
<div class="instrument" v-for="(instrument, index) in filteredInstruments" v-bind:key="index">
<img v-bind:src="aW5zdHJ1bWVudC5waG90bw==">
<span class="name">{{ instrument.name }}</span>
<span class="construction">{{ instrument.top }} / {{ instrument.backAndSides }}</span>
<span class="price">$ {{ instrument.price }}</span>
</div>
</div>
</transition-group>
`
}
我认为设置 v-bind:key="index"
可以满足这一点,但我得到了上面粘贴的错误.
I think that setting v-bind:key="index"
would take satisfy this, but I get the error pasted above.
推荐答案
您必须为您的
<div class="instruments">
提供唯一的密钥元素,因为<transition-group>
中的 元素,特别是直接子元素,总是需要具有唯一键属性.
You have to give a unique key to your
<div class="instruments">
element since elements inside a<transition-group>
, specifically the immediate children, are always required to have a unique key attribute.
如果您不想为 .instruments
提供密钥,则可以删除该元素并分配 tag
和 class
属性改为 <transition-group>
因为它呈现一个实际元素,默认情况下是 <span>
.
If you don't want to give a key to .instruments
, you can remove that element and assign a tag
and class
attributes to <transition-group>
instead since it renders an actual element which by default is a <span>
.
<transition-group name="fade" tag="div" class="instruments">
通过这种方式,警告将不再出现,因为直接子级 (.instrument
) 已为其分配了唯一键.
In this way, the warning would not appear anymore since the immediate children (.instrument
) have their unique keys assigned to them.
这篇关于过渡组的孩子必须有钥匙……但他们有钥匙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:过渡组的孩子必须有钥匙……但他们有钥匙


- 如何显示带有换行符的文本标签? 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01