Vue小练习--学生信息管理系统

使用Vue实现对数据的增删改查

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>
    * {
      margin0;
      padding0;
    }
    #example {
      width800px;
      margin50px auto;
    }
    .bkcolor {
      background-color: blueviolet;
    }
    form {
      width100%;
      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: {
          isShowfalse,
          isDisabledtrue,
          obj: {
            fonttrue,
            bkcolorfalse,
          },
          persons: [
            {
              num1,
              name"张三",
              score100,
              timeDate.now(),
            },
            {
              num2,
              name"李四",
              score90,
              timeDate.now(),
            },
            {
              num3,
              name"王五",
              score70,
              timeDate.now(),
            },
          ],
          person: {
            num"",
            name"",
            score"",
            // time:""
          },
        },
        computed: {},
        methods: {
          edit() {
            this.isDisabled = !this.isDisabled;
          },
          del(index) {
            this.persons.splice(index, 1);
          },
          morefunction () {
            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 + "") {
                //此处this.person.score为查询时输入的要查询的分数值,而person.score为数组中各对象的被查询的值
                return true;
              }
            });
            this.persons = search_Res_Persons;
          },
        },
      });
    </script>
  </body>
</html>

效果如图:
图片

JS-String.padStart Vuex Let's Start!

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×