单击“ VUE 3中的过渡组”之后显示hide div
显示新元素后
在单击旧元素隐藏使用动画之后,我需要使用动画模板
<div id="app">
<transition-group name="list">
<div style="cursor:pointer" v-for="(item,key,i) in array" :key="i" class="list-item" >
<div @click="select(key)">{{key}}</div>
</div>
</transition-group>
<div>
{{element}}
</div>
</div>
:脚本
export default {
name: 'App',
data() {
return {
element:"hello",
array: ["hello","hello1","hello2"],
}
},
methods:{
select(key){
this.element = this.array[key]
}
},
components: {
HelloWorld
}
}
:
.list-item {
transition: all 1s;
}
.list-leave-active {
display: none;
}
.list-enter {
opacity: 0;
}
I need that after clicking old element hide with animation and a new one also show with animation
Template:
<div id="app">
<transition-group name="list">
<div style="cursor:pointer" v-for="(item,key,i) in array" :key="i" class="list-item" >
<div @click="select(key)">{{key}}</div>
</div>
</transition-group>
<div>
{{element}}
</div>
</div>
Script:
export default {
name: 'App',
data() {
return {
element:"hello",
array: ["hello","hello1","hello2"],
}
},
methods:{
select(key){
this.element = this.array[key]
}
},
components: {
HelloWorld
}
}
Style:
.list-item {
transition: all 1s;
}
.list-leave-active {
display: none;
}
.list-enter {
opacity: 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅此snippet 受VUE官方doc https://v.vuejs.org/v2/guide/guide/transitions.html
更新列表(添加/删除项目)以触发Vue Transition的逻辑。
通过点击事件将索引传递,然后执行逻辑以更新您的数组
See this snippet inspired by Vue official doc https://v2.vuejs.org/v2/guide/transitions.html
You were missing the logic to update your list (add/remove items) to trigger vue transition.
Pass the index through click event then do your logic to update your array