Ste*_*ong 5 vue.js vuetify.js vee-validate
我想验证是否已使用 v-file-input 和 vee-validate 中的 ValidationProvider 选择文件。
下面是我的代码:
<v-flex>
<ValidationProvider rules="required" v-slot="{ errors }">
<v-file-input
show-size
accept=".xlsx"
placeholder="Click here to select your file"
label="File name"
:error="errors.length > 0"
:error-messages="errors[0]"
@change="selectFile"
>
</v-file-input>
</ValidationProvider>
</v-flex>
Run Code Online (Sandbox Code Playgroud)
不知怎的,验证有效,但即使在我选择了一个文件之后它也工作得很好:
我不确定我做错了什么?
Ste*_*ong 10
发现我必须这样做,不知道为什么我的上面不起作用:
rules: [
v => !!v || 'File is required',
v => (v && v.size > 0) || 'File is required',
]
Run Code Online (Sandbox Code Playgroud)
还有我的表格:
<v-flex>
<ValidationProvider :rules="rules" v-slot="{ errors }">
<v-file-input
show-size
accept=".xlsx"
placeholder="Click here to select your file"
label="File name"
:error="errors.length > 0"
:error-messages="errors[0]"
@change="selectFile"
>
</v-file-input>
</ValidationProvider>
</v-flex>
Run Code Online (Sandbox Code Playgroud)
https://codepen.io/subashdbc/pen/eYpVOKq
在这里发布代码以帮助有需要的人。
| 归档时间: |
|
| 查看次数: |
8471 次 |
| 最近记录: |