使用key值解决vue同名标签覆盖的问题

<!DOCTYPE html> <html lang="en">
<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script> <link href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.css" rel="stylesheet"> <link href="https://cdn.bootcss.com/animate.css/3.7.1/animate.css" rel="stylesheet"> <style> .div1 { width: 200px;height: 200px;background: red }
.move-enter { padding-left: 100px }
.move-enter-active { transition: all 2s }
.move-enter-to { padding-left: 0px }
.move-leave{ padding-left:0px } .move-leave-active{ transition: 2s all } .move-leave-to{ padding-left:100px }
  </style> </head>
<body> <div id="app"> <input type="button" name="" @click='change' value="按钮"> <transition name="move" mode=""> <div v-if='flag' :key=1>显示</div> <div v-else :key=2>隐藏</div> </transition> </div>

<script> var vm = new Vue({ el: '#app', data: { flag: true }, methods: { change() { this.flag = !this.flag } }
}); </script>
</body>
</html>
上一篇:动画——Vue中的动画封装


下一篇:放入Java应用程序时如何更改光标