1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Vue指令之v-for</title> </head> <body> <div id="app"> <ul> <li v-for="item in items">{{ item }}</li> </ul> <hr> <table border="1"> <tr> <th> 下标 </th> <th> 学生ID </th> <th> 学生姓名 </th> </tr> <tr v-for="(student, index) in students" :key="student.id"> <td> {{ index }} </td> <td> {{ student.id }} </td> <td> {{ student.name }} </td> </tr> </table> <hr> <div v-for="(value, key) in car"> {{ key }} : {{ value }} </div> </div> </body> <script src="js/vue.js" type="text/javascript"></script> <script type="text/javascript"> var vm = new Vue({ el: "#app", data: { items: ["华为手机", "小米手机", "苹果手机"], students: [{ id: 101, name: "张三" }, { id: 102, name: "李四" }, { id: 103, name: "王五" }, ], car: { brand: "比亚迪-汉", year: "2022", color: "black", price: 200000, run() { console.log("very fast") } } } }) </script> </html>
|