1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>Document</title>
    8. <script src="./lib/vue.js"></script>
    9. <style>
    10. .v-enter,
    11. .v-leave-to {
    12. opacity: 0;
    13. transform: translateX(200px)
    14. }
    15. .v-enter-active,
    16. .v-leave-active {
    17. transition: all 0.9s ease;
    18. }
    19. .my-enter,
    20. .my-leave-to {
    21. opacity: 0;
    22. transform: translateY(200px)
    23. }
    24. .my-enter-active,
    25. .my-leave-active {
    26. transition: all 0.9s ease;
    27. }
    28. </style>
    29. </head>
    30. <body>
    31. <div id="app">
    32. <input type="button" value="点击" @click="flag=!flag">
    33. <transition>
    34. <h3 v-show="flag">这里是H3</h3>
    35. </transition>
    36. <hr>
    37. <input type="button" value="点击11" @click="flag2=!flag2">
    38. <!-- 如果你使用一个没有名字的 <transition>,则 v- 是这些类名的默认前缀。如果你使用了 <transition name="my">,那么 v-enter 会替换为 my-enter。 -->
    39. <transition name="my">
    40. <h6 v-show="flag2">这里是H6</h6>
    41. </transition>
    42. </div>
    43. <script>
    44. var vm = new Vue({
    45. el: '#app',
    46. data: {
    47. flag: false,
    48. flag2: false
    49. },
    50. methods: {
    51. }
    52. });
    53. </script>
    54. </body>
    55. </html>

    1.gif