Blogger Information
Blog 62
fans 3
comment 1
visits 29718
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
vue中条件渲染与列表渲染演示
kiraseo_wwwkiraercom
Original
334 people have browsed it

vue中条件渲染与列表渲染演示

基本代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  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>vue中条件渲染与列表渲染演示</title>
  8. <script src="https://unpkg.com/vue@next"></script>
  9. </head>
  10. <body>
  11. <div class="app">
  12. <span>使用v-if 写法(条件渲染 v-if)</span>
  13. <fieldset>
  14. 成绩单
  15. <p>姓名:<span>{{result.name}}</span></p>
  16. <p>分数:<span>{{result.fraction}}</span></p>
  17. <p>评价:
  18. <span v-if="result.fraction>=90 ">{{grade[0]}}</span>
  19. <span v-else-if="result.fraction>=80 && result.fraction<90">{{grade[1]}}</span>
  20. <span v-else-if="result.fraction>=70 && result.fraction< 80">{{grade[2]}}</span>
  21. <span v-else>{{grade[3]}}</span>
  22. </p>
  23. </fieldset>
  24. <hr>
  25. <span>使用v-for写法 (列表渲染: v-for)</span>
  26. <ul>
  27. <li v-for="(fruit,index) of fruits" :key="index">第{{index+1}}种 : {{fruit}}</li>
  28. </ul>
  29. </div>
  30. </body>
  31. <script>
  32. Vue.createApp({
  33. data() {
  34. return {
  35. result:{
  36. name:'小名',
  37. fraction:'85',
  38. },
  39. grade: ['优', '良', '中 ', '及格'],
  40. fruits:['Strawberry', 'apple', 'cherry', 'orange', 'navel','orange', 'kumquat', 'papaya', 'grapefruit', 'Sydney', 'peach', 'longan', 'longan', 'lychee']
  41. };
  42. },
  43. }).mount('.app');
  44. </script>
  45. </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