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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Document</title> <script src="../Vue/vue.js"></script> </head> <style> * { margin: 0; padding: 0; } #example { width: 800px; margin: 50px auto; } .bkcolor { background-color: blueviolet; } form { width: 100%; display: flex; justify-content: space-between; } </style> <body> <div id="example"> <form v-show="isShow" :class="['bkcolor']"> <input type="text" placeholder="序号" v-model="person.num" /> <input type="text" placeholder="姓名" v-model="person.name" /> <input type="text" placeholder="分数" v-model="person.score" /> <input type="submit" value="新增" @click.prevent="add" /> <input type="submit" value="查询" @click.prevent="search" /> </form> <table> <tr> <th>序号</th> <th>姓名</th> <th>分数</th> <th>时间</th> <th>操作</th> </tr> <tr v-for="(person,index) in persons" :key="person.num"> <td> <input type="text" v-model="person.num" :disabled="isDisabled" /> </td> <td> <input type="text" v-model="person.name" :disabled="isDisabled" /> </td> <td> <input type="text" v-model="person.score" :disabled="isDisabled" /> </td> <td> <input type="text" :value="person.time | dateFormat" disabled /> </td> <td> <a href="#" @click.prevent="edit">编辑</a> <a href="#" @click.prevent="del(index)">删除</a> <a href="#" @click.prevent="more">更多操作</a> </td> </tr> </table> </div> <script> Vue.filter("dateFormat", function (value) { let time = new Date(value); let Year = time.getFullYear() + ""; let Month = time.getMonth() + 1 + ""; let Day = time.getDate() + ""; return `${Year}年${Month}月${Day}日`; }); var vm = new Vue({ el: "#example", data: { isShow: false, isDisabled: true, obj: { font: true, bkcolor: false, }, persons: [ { num: 1, name: "张三", score: 100, time: Date.now(), }, { num: 2, name: "李四", score: 90, time: Date.now(), }, { num: 3, name: "王五", score: 70, time: Date.now(), }, ], person: { num: "", name: "", score: "", }, }, computed: {}, methods: { edit() { this.isDisabled = !this.isDisabled; }, del(index) { this.persons.splice(index, 1); }, more: function () { this.isShow = !this.isShow; }, add() { this.person.time = Date.now(); this.persons.push(this.person); this.person = { num: "", name: "", score: "", }; }, search() { let search_Res_Persons = this.persons.filter((person) => { if (this.person.score === person.score + "") { return true; } }); this.persons = search_Res_Persons; }, }, }); </script> </body> </html>
|
评论