1.vant的图片上传组件,没有文件上传功能,这对我们很不友好,于是我们自己手写
2. html
<div class="upLoad">
<van-uploader :after-read="afterRead" v-model="fileList">
<van-button><van-icon name="plus" size="30" /></van-button>
</van-uploader>
</div>
3. data
//这是文件列表
fileList: [],
//这个是接口的文件参数
up_files: [],
4. js
//文件图片上传
afterRead(fileObj) {
// 上传状态
this.fileLoading = true;
fileObj.status = "uploading";
// 状态提示
fileObj.message = "上传中...";
// 声明form表单数据
const formData = new FormData();
// 添加文件信息
formData.append("file", fileObj.file);
// 上传接口调用
this.$api.Up_files(formData).then((res) => {
// 存储返回数据
console.log(res);
this.turn.up_files.push(res.id);
fileObj.status = "done";
this.fileLoading = false;
console.log(this.turn.up_files);
}).catch((e) => {
console.log(e, 11);
});
},