Blogger Information
Blog 28
fans 0
comment 0
visits 13125
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
列表渲染与条件渲染指令演示
手机用户1594223549
Original
567 people have browsed it

1.输出结果

2.代码部分

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>列表渲染与条件渲染指</title>
  8. <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  9. </head>
  10. <body>
  11. <div class="app">
  12. <!-- v-for指令快速循环输出列表 -->
  13. <ul>
  14. <p>列表渲染</p>
  15. <!-- key: diff算法,实现高效的渲染 -->
  16. <li v-for="(city,key) of cities" :key="key">{{key}} : {{city}}</li>
  17. </ul>
  18. </div>
  19. <hr />
  20. <div class="app1">
  21. <ul>
  22. <p>条件渲染</p>
  23. <!-- v-if: 条件渲染指令 -->
  24. <!-- if-else,if else if -->
  25. <p v-if="point < 1000">{{grade[0]}}</p>
  26. <p v-if="point >= 1000 && point < 2000">{{grade[1]}}</p>
  27. <p v-else-if="point >= 2000 && point < 3000">{{grade[2]}}</p>
  28. <p v-else-if="point >= 3000 && point < 4000">{{grade[3]}}</p>
  29. <p v-else-if="point >= 4000">{{grade[4]}}</p>
  30. </ul>
  31. </div>
  32. <script>
  33. const app = Vue.createApp({
  34. data() {
  35. return {
  36. // Array
  37. cities: ["北京", "上海", "天津"],
  38. };
  39. },
  40. });
  41. const vm = app.mount(".app");
  42. const app1 = Vue.createApp({
  43. data() {
  44. return {
  45. // 会员级别
  46. grade: ["纸片会员", "木头会员", "铁皮会员", "金牌会员", "非会员"],
  47. // 积分
  48. point: 6000,
  49. };
  50. },
  51. });
  52. const vm1 = app1.mount(".app1");
  53. </script>
  54. </body>
  55. </html>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post