搭建小程序端
用vant组件
<van-uploader file-list="{
{ fileList }}" bind:after-read="afterRead" deletable="{
{ true }}" />
vant官网写的好像有点问题(自接用会报错)
data: {
deletable: false,
fileList: [],
},
afterRead(event) {
var that = this;
const {
file } = event.detail;
// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
wx.uploadFile({
url: 'http://test:9001/upload', // 仅为示例,非真实的接口地址
filePath: file.url,
name: 'file',
formData: {
user: 'test' },
success(res) {
// 上传完成需要更新 fileList
const {
fileList = [] } = that.data;
fileList.push({
file, url: res.data });
that.