6_v-if.html 942 B

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