繁体   English   中英

使用 vue.js 验证 laravel 中的文件

[英]validate files in laravel using vue.js

我正在尝试上传文件并验证使用 dropzone/vue 库的 laravel 和 vue.js 中的文件,该文件具有各种 mimetypes,例如 doc、docx、xls、xlsx、ppt、jpg、jpeg、ptx、gif、png, txt,这是我的 Laravel 代码片段。 代码看起来不错,但我仍然无法验证 jpg 和 jpeg mime 类型。 我想知道如何将错误传递给 vue 组件

public function postFileUpload(Request $request)
    {
        $validator = Validator::make($request->all(),
            ['file' => 'required|mimes:png,gif,pdf,jpg,jpeg,txt|max:8192']
        );
        if ($validator->fails()) {
            echo 'in';
            exit();
//            return redirect()->back()->withErrors($validator->errors());
//            return redirect()->back()->withErrors($validator)->withInput()->withError('please select file type');
        } else {

            echo 'out';
            exit();
        }
    }

考虑使用 vee-validate: http : //vee-validate.logaretm.com/validation.html#rule-ext在客户端验证文件

v-validate.reject="'required|ext:png,gif,pdf,jpg,jpeg,txt|size:8192'"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM