因此,即使ValidationProvider提示错误,我也会输入错误文本,但是submit form应该运行saveAccount。即使文本是可以的,它也不能工作。我没有错误,没有反应,然后我点击提交按钮。我使用的是veeValidate 3.3.0
<template>
<ValidationObserver v-slot="{ handleSubmit }"> //this and next line seems to won't work
<q-form @submit="handleSubmit(saveAccount)" >
<ValidationProvider rules="secret" v-slot="{ errors }">
<q-input
v-model="account.password"
outlined
:label="$t('wizzard.password')"
class="q-mb-sm"
color="orange-7"
></q-input>
<span>{{ errors[0] }}</span>
</ValidationProvider>
<ButtonsBar
:label="$t('wizzard.Create account')"
:nextBt="nextBt"
/>
</q-form>
</ValidationObserver>
</template>
<script lang="ts">
import { Component, Emit, Mixins } from 'vue-property-decorator'
import { ValidationProvider, ValidationObserver } from 'vee-validate'
...
import './utils/VeeRules'
@Component({
components: {
...
ValidationProvider,
ValidationObserver
}
})
export default class CreateAccount extends Mixins(QuasarStyles) {
...
@Emit()
saveAccount (): AccountType | false {
if(this.account.email !== '' && this.account.password !== '' && this.account.password === this.account.confirmPassword){
return this.account
} else {
return false
}
}
}
</script>和VeeRules中的规则:
import { extend } from 'vee-validate';
export const passwordLength = extend('secret', {
validate: value => value === 'example',
message: 'This is not the magic word'
}); 发布于 2020-06-04 21:47:46
您可以尝试在提交时添加.prevent吗?
<q-form @submit.prevent="handleSubmit(saveAccount)" > https://stackoverflow.com/questions/62190646
复制相似问题