6_v-if.html 983 B

1234567891011121314151617181920212223242526272829303132333435
  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. <title>Document</title>
  7. <script src="./js/vue.js"></script>
  8. </head>
  9. <body>
  10. <div id="app">
  11. <!-- v-if 直接移除元素 -->
  12. <h1 v-if="isShow">hello world</h1>
  13. <h1 v-else>你好世界</h1>
  14. <!-- v-show 仅能控制元素的显示及隐藏 -->
  15. <!-- v-show 与 v-if 的区别 -->
  16. <!-- v-show 控制的是display属性 none -->
  17. <!-- <h1 v-show="isShow">hello world</h1> -->
  18. <button @click="toogleShow">显示/隐藏</button>
  19. </div>
  20. <script>
  21. new Vue({
  22. el:"#app",
  23. data:{
  24. isShow:true
  25. },
  26. methods:{
  27. toogleShow(){
  28. // this.isShow = false;
  29. this.isShow = !this.isShow;
  30. }
  31. }
  32. })
  33. </script>
  34. </body>
  35. </html>