首页 > 编程知识 正文

vue如何控制页面展示多次,vue按钮上滑事件

时间:2023-05-06 08:42:10 阅读:205867 作者:4730

实现单击一个按钮后,切换盒子的展开和收起状态

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>单击按钮实现盒子的展开和收起</title></head><script src="./JS/vue.js"></script><style> /* 初始状态 */ #app{ margin: 0,auto; } .box{ margin: 20px; width: 150px; height: 200px; background-color: cadetblue; text-align: center; line-height: 200px; } button{ margin-left: 20px; } /* 进入和离开的过程 */ .Box-enter-active,.Box-leave-active{ transition: all 2s; } .Box-enter,.Box-leave-to{ width: 0px; height: 0px; } .Box-enter-to,.Box-leave{ width: 150px; height: 200px; }</style><body> <div id="app"> <button @click="cancel">{{mag}}</button> <transition name="Box"> <div class="box" v-if="show"></div> </transition> </div><script> var vm =new Vue({ el:'#app', data:{ show:true, mag:'收起' }, methods:{ cancel(){ this.show=!this.show; if(this.show==false){ this.mag='展开'; } else if(this.show==true){ this.mag='收起'; } } } })</script></body></html>


版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。