如何使用 Vee-Validate 验证选择选项

TJ *_*ems 6 vue.js vee-validate

浏览 vee-validates 文档,我没有看到任何用于验证选择输入的内容。所以我的问题是你能验证选择吗?目前我尝试的内容不会显示错误消息...

这是代码

<select id="category" v-model="client.category" name="Category Type" v-validate="'required'">
  <option disabled>{{option}}</option>
  <option v-for="category in categories" :key="category.id" :value="category">{{ category }}</option>
 </select>
 <spanv-show="errors.has('Category Type')">{{ errors.first('Category Type') }}</span>
Run Code Online (Sandbox Code Playgroud)

小智 1

v-model="client.category" 
Run Code Online (Sandbox Code Playgroud)

如果您的 v-model 是一个复杂的对象,则 v-validate 不起作用。我会使用字符串/数字来绑定选项->选择,然后使用一些函数来模拟对象中的其余属性。