闫增涛
2024-05-30 c74a9956a74475199b23bf37385135cae1076f85
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
<template>
  <table>
    <thead>
      <tr>
        <th class="time">时间</th>
        <th class="name">保育机构名称</th>
        <th class="special">特点</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1949年以前</td>
        <td><input class="inputItem" type="text" /></td>
        <td><input class="inputItem" type="text" /></td>
      </tr>
      <tr>
        <td>1949-1980年</td>
        <td><input class="inputItem" type="text" /></td>
        <td><input class="inputItem" type="text" /></td>
      </tr>
      <tr>
        <td>1980-1990年</td>
        <td><input class="inputItem" type="text" /></td>
        <td><input class="inputItem" type="text" /></td>
      </tr>
      <tr>
        <td>1990-2000年</td>
        <td><input class="inputItem" type="text" /></td>
        <td><input class="inputItem" type="text" /></td>
      </tr>
      <tr>
        <td>2000年</td>
        <td><input class="inputItem" type="text" /></td>
        <td><input class="inputItem" type="text" /></td>
      </tr>
    </tbody>
  </table>
</template>
 
<script>
export default {
  data() {
    return {
      tableData: [
        { name: "John", age: 30, address: "New York" },
        { name: "Jane", age: 25, address: "Los Angeles" },
        { name: "Doe", age: 40, address: "Chicago" },
      ],
      editIndex: -1,
      editedRow: {},
    };
  },
  methods: {
    handleRowClick(row, event, column) {
      if (this.editIndex === column) {
        // 如果点击的是已经编辑的行,则不做任何操作
        return;
      }
      this.editIndex = column;
      // 克隆当前行的数据,以便编辑时可以取消修改
      this.editedRow = { ...row };
    },
    handleEdit(index, row) {
      // 编辑按钮点击事件
      this.editIndex = index;
      this.editedRow = { ...row };
    },
    handleSave(index) {
      // 保存编辑内容
      this.tableData[index] = { ...this.editedRow };
      this.editIndex = -1;
    },
    handleCancel() {
      // 取消编辑
      this.editIndex = -1;
    },
  },
};
</script>
<style scoped>
table {
  border-collapse: collapse;
  width: 100%;
}
 
.time {
  width: 150px;
}
 
th,
td {
  border: 1px solid #ddd;
  padding: 5px;
  text-align: center;
  box-sizing: border-box;
}
 
.inputItem {
  width: 90%;
  height: 32px;
  border: 0;
  font-size: 18px;
}
 
th {
  background-color: #f49a4c;
}
</style>