更新记录

0.1.2.6(2021-10-19)

加入组件的全局样式

0.1.2.5(2021-04-06)

组件兼容性

0.1.2.4(2021-02-22)

更新flex样式不兼容

查看更多

平台兼容性

Vue2 Vue3
×
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.0.0 × × × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × × × × × ×

uploader

参数名 必填 参数 说明
fileList [] ----参考vant-ui
mutiple 布尔值 是否上传多个
maxUpload 1 最大上传数量 默认1
previewSize 160rpx 字符类型 默认160rpx
deletable 布尔值 是否开启关闭按钮

事件

事件名 返回参数 说明
after-read fileList 结构参考uni-chooseImage res.fileLists 文档传送门
delete Index 返回删除图片的索引,要做删除操作 删除对应fileList索引

用法

<Uploader preview-size="180rpx" :mutiple="true" :maxUpload="5" :file-list="fileList" @after-read="afterRead" @delete="onDelete" />
data() {
  return {
    fileList: [],
  }
},
methods: {
  afterRead(e) {
      // afterRead传过来的是一个中间文件对象
        const file = e

      uni.showLoading({
        title: '正在上传中...',
        mask: true
      });
      file.map(item => {
        uploadFile(item.path).then(res => {
            uni.hideLoading();
                // 上传完毕后按照后端服务器返回的数据来操作fileList
            //
            this.fileList.push(res)
        });
      })
  },
  // 上传到你的服务器
  uploadFile(path) {
    return new Promise(resolve => {
        uni.uploadFile({
          url: '', //你服务器上的url
          filePath: path,
          name: 'file',
          fileType: 'image',
          cloudPath: '',
          success: res => {
            console.log('uploadFile res ==> ', res)
            let data = JSON.parse(res.data);

            if (data.code == 1) {
              resolve(data.data);
            }
          },
          fail: (err) => {
               console.log('error ==>', err)
          }
        });
      });
  },
  handleImage(index) {
     this.fileList.splice(index)
  }
}

后端返回的res数据结构

请自行根据服务器返回的res操作fileList,请不要过分依赖该示例中的uploadFile方法,按需更改

code: 1
data: {
  base_url: "/uploads/images/user/20210205/aadb448bc83c18782b7503ce8006f95f.jpg",
  name: "K4GZIiUyXyvpa28f14c65f4b60913d5c4ce849ec905f.jpg",
  url: "xxxxxxx/uploads/images/user/20210205/aadb448bc83c18782b7503ce8006f95f.jpg"
}
debug: {request: {get: [], post: [],…}}
msg: "ä¸ä¼ æ件æå"
show: 0
time: "0.043755"

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问