Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

javascript - Nuxt应用程序中的表单验证始终返回true(Form validation in Nuxt application returns always true)

I just start using vee-validate in my project.

(我只是在项目中开始使用vee-validate。)

I have following code in my component where is simple form group with validation

(我的组件中有以下代码,其中是带有验证的简单表单组)

    <ValidationObserver ref="observer" v-slot="{ invalid }">
        <b-form @submit.prevent="onSubmit" novalidate>
            <b-form-group label="Amount">
                <ValidationProvider name="amount" rules="required|min_value:0" v-slot="{ errors }">
                    <b-form-input
                        :state="errors.length == 0"
                        v-model="form.amount"
                        type="text"
                        placeholder="Amount"
                    ></b-form-input>
                    <b-form-invalid-feedback :state="errors.length == 0">{{errors.join('. ')}}</b-form-invalid-feedback>
                </ValidationProvider>
            </b-form-group>
        </b-form>
    </ValidationObserver>

I have imported ValidationObserver and ValidationProvider in component but validation behave weird.

(我已经在组件中导入了ValidationObserver和ValidationProvider,但是验证行为很奇怪。)

在此处输入图片说明

On picture you can see default behavior.

(在图片上您可以看到默认行为。)

It is green from start and doesn't matter what I write or if I submit as empty.

(从一开始就是绿色,无论我写什么或提交为空都无关紧要。)

It is always green.

(它总是绿色的。)

Submit method looks like this:

(Submit方法如下所示:)

       async onSubmit() {
            let validate = await this.$refs.observer.validate();
            console.log('VALID: ', validate)
        },

and gives me always true.

(并给我永远的真实。)

I am using nuxt 2.9.x and vee-validate 3.1.x

(我正在使用nuxt 2.9.x和vee-validate 3.1.x)

  ask by Denis Stephanov translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...