|
35 | 35 |
|
36 | 36 | <el-table-column min-width="300px" label="标题">
|
37 | 37 | <template slot-scope="scope">
|
38 |
| - <el-input v-show="scope.row.edit" size="small" v-model="scope.row.title"></el-input> |
39 |
| - <span v-show="!scope.row.edit">{{ scope.row.title }}</span> |
| 38 | + <template v-if="scope.row.edit"> |
| 39 | + <el-input class="edit-input" size="small" v-model="scope.row.title"></el-input> |
| 40 | + <el-button class='cancel-btn' size="small" icon="el-icon-refresh" type="warning" @click="cancelEdit(scope.row)">cancel</el-button> |
| 41 | + </template> |
| 42 | + <span v-else>{{ scope.row.title }}</span> |
40 | 43 | </template>
|
41 | 44 | </el-table-column>
|
42 | 45 |
|
43 | 46 | <el-table-column align="center" label="编辑" width="120">
|
44 | 47 | <template slot-scope="scope">
|
45 |
| - <el-button :type="scope.row.edit?'success':'primary'" @click='scope.row.edit=!scope.row.edit' size="small" icon="edit">{{scope.row.edit?'完成':'编辑'}}</el-button> |
| 48 | + <el-button v-if="scope.row.edit" type="success" @click="confirmEdit(scope.row)" size="small" icon="el-icon-circle-check-outline">完成</el-button> |
| 49 | + <el-button v-else type="primary" @click='scope.row.edit=!scope.row.edit' size="small" icon="el-icon-edit">编辑</el-button> |
46 | 50 | </template>
|
47 | 51 | </el-table-column>
|
48 | 52 |
|
@@ -84,12 +88,40 @@ export default {
|
84 | 88 | fetchList(this.listQuery).then(response => {
|
85 | 89 | const items = response.data.items
|
86 | 90 | this.list = items.map(v => {
|
87 |
| - this.$set(v, 'edit', false) |
| 91 | + this.$set(v, 'edit', false) // https://vuejs.org/v2/guide/reactivity.html |
| 92 | + v.originalTitle = v.title // will be used when user click the cancel botton |
88 | 93 | return v
|
89 | 94 | })
|
90 | 95 | this.listLoading = false
|
91 | 96 | })
|
| 97 | + }, |
| 98 | + cancelEdit(row) { |
| 99 | + row.title = row.originalTitle |
| 100 | + row.edit = false |
| 101 | + this.$message({ |
| 102 | + message: 'The title has been restored to the original value', |
| 103 | + type: 'warning' |
| 104 | + }) |
| 105 | + }, |
| 106 | + confirmEdit(row) { |
| 107 | + row.edit = false |
| 108 | + row.originalTitle = row.title |
| 109 | + this.$message({ |
| 110 | + message: 'The title has been edited', |
| 111 | + type: 'success' |
| 112 | + }) |
92 | 113 | }
|
93 | 114 | }
|
94 | 115 | }
|
95 | 116 | </script>
|
| 117 | + |
| 118 | +<style scoped> |
| 119 | +.edit-input { |
| 120 | + padding-right: 100px; |
| 121 | +} |
| 122 | +.cancel-btn { |
| 123 | + position: absolute; |
| 124 | + right: 15px; |
| 125 | + top: 13px; |
| 126 | +} |
| 127 | +</style> |
0 commit comments