9.条件渲染.html 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. </head>
  8. <body>
  9. <div id="app">
  10. <!--
  11. 条件渲染:
  12. 1.v-if v-else v-else-if
  13. 2.v-show
  14. v-show与v-if区别:
  15. 1.当频繁使用变量渲染的时候 使用v-show;逻辑判断v-if
  16. 2.v-if 消耗性能
  17. 3.v-show 单纯显示隐藏
  18. -->
  19. 成绩:{{score}}
  20. <h3>if判断</h3>
  21. <p v-if="score >= 90">优秀</p>
  22. <p v-else-if="score >= 80">良好</p>
  23. <p v-else-if="score >= 70">凑合</p>
  24. <p v-else-if="score >= 60">完美</p>
  25. <p v-else>咦~</p>
  26. <hr>
  27. <h3>show判断</h3>
  28. <p v-show="score >= 90">优秀</p>
  29. <p v-show="score >= 80">良好</p>
  30. <p v-show="score >= 70">凑合</p>
  31. <p v-show="score >= 60">完美</p>
  32. <p v-show="score < 60">咦~</p>
  33. </div>
  34. <script src="./vue.js"></script>
  35. <script>
  36. var app = new Vue({
  37. data:{
  38. score: Math.ceil(Math.random()*100)
  39. }
  40. }).$mount("#app")
  41. </script>
  42. </body>
  43. </html>