Skip to content

Commit

Permalink
fix[complex-table]: double-clicking the Confirm button triggers the r…
Browse files Browse the repository at this point in the history
…equest twice
  • Loading branch information
codersjj committed May 11, 2022
1 parent 0caa975 commit a8c55f8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/views/table/complex-table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<el-button @click="dialogFormVisible = false">
Cancel
</el-button>
<el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
<el-button :loading="confirmLoading" type="primary" @click="dialogStatus==='create'?createData():updateData()">
Confirm
</el-button>
</div>
Expand Down Expand Up @@ -223,7 +223,8 @@ export default {
timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
title: [{ required: true, message: 'title is required', trigger: 'blur' }]
},
downloadLoading: false
downloadLoading: false,
confirmLoading: false
}
},
created() {
Expand Down Expand Up @@ -282,13 +283,15 @@ export default {
this.resetTemp()
this.dialogStatus = 'create'
this.dialogFormVisible = true
this.confirmLoading = false
this.$nextTick(() => {
this.$refs['dataForm'].clearValidate()
})
},
createData() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
this.confirmLoading = true
this.temp.id = parseInt(Math.random() * 100) + 1024 // mock a id
this.temp.author = 'vue-element-admin'
createArticle(this.temp).then(() => {
Expand All @@ -309,13 +312,15 @@ export default {
this.temp.timestamp = new Date(this.temp.timestamp)
this.dialogStatus = 'update'
this.dialogFormVisible = true
this.confirmLoading = false
this.$nextTick(() => {
this.$refs['dataForm'].clearValidate()
})
},
updateData() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
this.confirmLoading = true
const tempData = Object.assign({}, this.temp)
tempData.timestamp = +new Date(tempData.timestamp) // change Thu Nov 30 2017 16:41:05 GMT+0800 (CST) to 1512031311464
updateArticle(tempData).then(() => {
Expand Down

0 comments on commit a8c55f8

Please sign in to comment.