Blogger Information
Blog 27
fans 1
comment 2
visits 90502
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Vue中的列表渲染和条件指令渲染实例
          
Original
521 people have browsed it
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  9. <title>1121作业</title>
  10. <!-- 实例演示列表渲染与条件渲染指令-->
  11. </head>
  12. <body>
  13. <div id="app">
  14. <h3 :style="{color:red}">列表渲染:v-for</h3>
  15. <ul>
  16. <li v-for="(item,key) of list" :key="key">{{item}}</li>
  17. </ul>
  18. </div>
  19. <hr>
  20. <div id="object">
  21. <h3 v-bind:style="{color:bl}" >条件渲染:v-if</h3>
  22. <p v-if="id === 1">{{arr[0]}}</p>
  23. <p v-else-if="id ===2">{{arr[1]}}</p>
  24. <p v-else-if="id ===3">{{arr[2]}}</p>
  25. <p v-else-if="id ===4">{{arr[3]}}</p>
  26. <p v-else>{{arr[4]}}</p>
  27. </div>
  28. <script>
  29. // 列表渲染:v-for
  30. // 应用实例
  31. const app = Vue.createApp({
  32. data(){
  33. return{
  34. list:[1,2,3,4,5],
  35. red:'red',
  36. }
  37. }
  38. })
  39. // 根组件实例:绑定
  40. app.mount('#app')
  41. // 条件渲染:v-if
  42. const object = Vue.createApp({
  43. data(){
  44. return{
  45. bl:'blue',
  46. arr:['1==A','2==B','3==C','4==D','非法数据!'],
  47. id:1
  48. }
  49. }
  50. })
  51. const vm = object.mount("#object")
  52. // 动态修改
  53. vm.id = 1 // 1==A
  54. vm.id = 2 // 2==B
  55. vm.id = 3 // 3==C
  56. vm.id = 800 // 非法数据!
  57. </script>
  58. </body>
  59. </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