Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vuejs2 Vuejs+VeeValidate将参数传递给子组件_Vuejs2_Vee Validate - Fatal编程技术网

Vuejs2 Vuejs+VeeValidate将参数传递给子组件

Vuejs2 Vuejs+VeeValidate将参数传递给子组件,vuejs2,vee-validate,Vuejs2,Vee Validate,我创建了一个名为Month的组件,在其中我传递了一些道具: <template> <select :id="id" :name="id" :class="extraClasses" :v-validate="{required: req}"> <option v-if="def" selected disabled :value="null">{{def}}</option> <option v-if="!def" sel

我创建了一个名为Month的组件,在其中我传递了一些道具:

<template>
  <select :id="id" :name="id" :class="extraClasses" :v-validate="{required: req}">
    <option v-if="def" selected disabled :value="null">{{def}}</option>
    <option v-if="!def" selected disabled :value="null">Month</option>
    <option v-for="(month, index) in months" :key="index" :value="pad(index)">{{month}}</option>
  </select>
</template>
如果我将其称为以下内容,它们都能正常工作:

<Month id="dob_month" extraClasses="month" def="Initial month" />
但是,当我尝试通过验证部分时,VeeValidate似乎忽略了它:

<Month id="dob_month" req="true" />
是否有一种方法可以在不使用消息总线的情况下将验证传递给子级,以便在父级中执行类似的操作:

<fieldset id="dob" :class="{'has-error': errors.has('dob_day') || errors.has('dob_month') || errors.has('dob_year') }">
  <legend class="a-required">Date of Birth</legend>
  <input type="hidden" id="date_of_birth" name="date_of_birth" />
  <select id="dob_day" name="dob_day" v-validate="'required'">
    <option selected disabled value="">Day</option>
    <option v-for="day in monthDays" :key="day" :value="day">{{day}}</option>
  </select>
  <Month id="dob_month" req=true />
  <Year id="dob_year" req="true" />
</fieldset>

或者我将无法在父级和子级之间正确填充/传播错误?

您不需要使用:进行v-validate。其值已在vee validate内插值。 像这样的方法应该会奏效:

  <select :id="id" :name="id" :class="extraClasses" v-validate="{required: req}">

查看此代码笔,例如使用min规则和局部变量

不清楚u传递的内容和不起作用的内容抱歉,我在父级传递给子级的内容是,子组件有:但是它似乎没有真正注意到req PROP谢谢!这么小的变化