修改编辑店铺时form的校验方式

This commit is contained in:
zhl 2021-04-19 20:08:08 +08:00
parent 7d2e069349
commit b23b80c2f0

View File

@ -93,7 +93,7 @@ export default class extends Vue {
private postForm = Object.assign({}, defaultShopData) private postForm = Object.assign({}, defaultShopData)
private loading = false private loading = false
private rules = { private rules = {
title: [{ validator: this.validateRequire }], name: [{ validator: this.validateRequire }],
} }
private tempTagView?: ITagView private tempTagView?: ITagView
@ -146,9 +146,10 @@ export default class extends Vue {
document.title = `${title} - ${this.postForm._id}` document.title = `${title} - ${this.postForm._id}`
} }
private submitForm() { private async submitForm() {
(this.$refs.postForm as Form).validate(async valid => { const form = <Form>this.$refs.postForm
if (valid) { try {
await form.validate()
this.loading = true this.loading = true
await saveShop(this.postForm) await saveShop(this.postForm)
this.loading = false this.loading = false
@ -158,11 +159,10 @@ export default class extends Vue {
type: 'success', type: 'success',
duration: 2000 duration: 2000
}) })
} else { } catch (err) {
console.error('Submit Error!') console.error('Submit Error!')
return false return false
} }
})
} }
private draftForm() { private draftForm() {