如何在VeeValidate4上正确设置插槽。

huangapple go评论67阅读模式
英文:

How to set up slot correctly on VeeValidate4

问题

I am rewriting a bunch of components from VeeValidate 3 to VeeValidate 4 and I am facing some issues when it comes to adding slots to render complex HTML.

This is my code:

<template>
  <div>
    <Field
      :name="$t('form.email')"
      tag="div"
      :rules="`required|email`"
      class="form-input"
      v-slot="{ field, blur, updateInput }"
    >
      <label class="form-input-label">
        <small class="form-input-title d-block" v-t="'form.email'"></small>

        <input
          type="text"
          class="form-input-field d-block"
          v-bind="field"
          :disabled="isDisabled"
          @input="updateInput"
          @blur="blur"
        >

        <p class="form-input-error"></p>
      </label>
    </Field>
  </div>
</template>

According to the documentation, I should bind the Field to the rendered input via a scoped slot.

But in the console, I am getting the following error:

TypeError: Cannot read properties of undefined (reading 'field')

Can you help me find the issue?
Thanks

英文:

I am rewriting a bunch of components from VeeValidate 3 to VeeValidate4 and I am facing some issue when it comes to add use slots to render complex HTML.

This is my code:

&lt;template&gt;
&lt;div&gt;
    &lt;Field
      :name=&quot;$t(&#39;form.email&#39;)&quot;
      tag=&quot;div&quot;
      :rules=&quot;`required|email`&quot;
      class=&quot;form-input&quot;
      v-slot=&#39;{ field, blur, updateInput }&#39;
    &gt;
      &lt;label
        class=&quot;form-input-label&quot;
      &gt;
        &lt;small
          class=&quot;form-input-title d-block&quot;
          v-t=&quot;&#39;form.email&#39;&quot;
        /&gt;

        &lt;input
          type=&quot;text&quot;
          class=&quot;form-input-field d-block&quot;
          v-bind=&quot;field&quot;
          :disabled=&quot;isDisabled&quot;
          @input=&quot;updateInput&quot;
          @blur=&quot;blur&quot;
        &gt;

        &lt;p class=&quot;form-input-error&quot; /&gt;
      &lt;/label&gt;
    &lt;/Field&gt;
  &lt;/div&gt;
&lt;/template&gt;

According to the documentation, I should bind the Field to the rendered input via a scoped slot.

But in the console I am getting the following error

TypeError: Cannot read properties of undefined (reading &#39;field&#39;)

Can you help me find the issue?
Thanks

答案1

得分: 0

我只是缺少了关于 Field 对象的全局导入。

英文:

I simply was missing a global import for the Field object.

huangapple
  • 本文由 发表于 2023年5月25日 17:38:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76330875.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定