vant-upload上传

在使用vant组件vant-upload上传图片的时候,代码如下:

//html
<van-uploader :after-read="onRead" multiple>
                <van-icon name="photograph"/>
            </van-uploader>

//js
onRead(file, detail) {
                let self = this;
                let data = new FormData();
                if (file instanceof Array) {
                    file.forEach((item, index) => {
                        window.console.log('index', index);
                        self.data.append(`file${index}`, item.file);
                    })
                } else {
                    self.data.append(`file`, file.file)
                }
                window.console.log('file:', file, 'detail:', detail);
                /*this.upload(data)
                    .then((res) => {
                        window.console.log('res:', res);
                    })
                    .catch(reason => {
                        window.console.log(reason);
                    })*/
            }

后端正常接收

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容