vant-upload上传

2019-08-29  本文已影响0人  IT宝哥哥

在使用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);
                    })*/
            }

后端正常接收

上一篇 下一篇

猜你喜欢

热点阅读