
html
| <van-uploader v-model="fileList" multiple :max-count="3" :after-read="afterRead" preview-size="95"/> |
复制
js
| afterRead(file) { |
| let _this = this; |
| |
| console.log(file); |
| |
| console.log(this.fileList) |
| |
| const formData = new FormData(); |
| formData.append("image", file.file); |
| $.ajax({ |
| url: "/member/upload/{$agentState}", |
| type: 'POST', |
| |
| contentType: false, |
| processData: false, |
| data: formData, |
| success: function (res) { |
| _this.fileList.forEach((ele, i) => { |
| if (ele.file.lastModified == file.file.lastModified) { |
| _this.fileList[i].content = res.data.url |
| } |
| }); |
| |
| } |
| }) |
| }, |
复制
我们首先将上传的文件添加到fileList中,然后创建一个新的FormData对象,并将文件添加到其中。接下来,我们使用jQuery的ajax()方法将FormData发送到服务器。在这里,我们需要将contentType和processData设置为false,这样jQuery就不会对数据进行自动处理