Skip to content
官方QQ交流群
pc端ui:468705115   点此加入
移动端ui:468217742   点此加入
技术交流1:87208295   点此加入
技术交流2:787747122   点此加入
官网
云控制台
开放平台
关注微信公众号
代码仓库: 码云

cv-upload-file 文件上传

简要

  • 使 el-upload 组件更简单、好用

全局配置

js
 
// 注册 cv-pc-ui
Vue.use(cvPcUI, {
  // 专门设置全局的 cvUploadFile 属性
  'cvUploadFile': {
    fileSize: 10
    // 上传地址
    upAction: 'https://jsonplaceholder.typicode.com/posts',
    isCanDelete: false,
    // 上传后对响应处理, 拼接为一个URL地址
    upResponseFn(response, file) {
      // 根据响应结果, 设置 URL
      return {
        name: file.name,
        url: 'https://xxx.com/file/' + response.path, // 示例而已
        size: file.size
      }
    }
  }
})

示例

::: demo

vue
<template>
  <div>
    <cvUploadFile :action="'http://xxx.xxx'"></cvUploadFile>
  </div>
</template>
<script>
export default {
  data() {
    return {
      image1: '',
      image2: '',
      image3: '',
      images: [],
      formData: {},
      formDesc: {
        avatar: {
          label: '头像',
          type: 'ggUploadImage',
          attrs: {
            fileSize: 3,
            action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
            upResponseFn(response, file) {
              // 需要返回一个 URL
              return file.url;
            }
          }
        },
        covers: {
          label: '封面',
          type: 'ggUploadImage',
          attrs: {
            drag: true, // 多张
            action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
            upResponseFn(response, file) {
              return file.url;
            }
          }
        }
      }
    };
  },
  methods: {
    handleResponse(response, file, fileList) {
      return file.url;
    },
    handleRequest(data) {
      console.log(data);
      return Promise.resolve();
    },
    handleSuccess() {
      this.$message.success('提交成功');
    }
  },
  mounted() {}
};
</script>

:::

属性

属性名类型默认值说明
v-model/modelValueString, Object, Array-文本内容
upActionString-必选参数,上传的地址
upNameStringfile文件名
upHeadersObject-上传图片携带的header
upDataObject-自定义上传数据, 例如
upCookieBooleanfalse是否需要带cookie
upAcceptString-接受上传的文件类型
upResponseFnFunction-上传成功的进一步处理
multipleBooleantrue是否支持多选文件
limitNumber-最大允许上传个数
beforeRemoveFunction-删除前的操作
disabledBoolean-是否禁用
fileSizeNumber-图片大小限制 (MB)
fileTypeArray-文件类型, 例如['png', 'jpg', 'jpeg']
isCanDownloadBooleantrue是否显示下载
isCanDeleteBooleantrue是否可删除
isCanUploadSameBooleantrue是否可上传相同文件
isShowSizeBooleantrue是否显示文件大小
isShowTipBooleantrue是否显示提示
isShowSuccessTipBooleantrue是否显示提示

事件

事件名称说明回调参数
remove当文件被删除时触发(file, fileList)
success文件上传成功时触发(file, fileList)
error上传失败时触发(error)

相关链接

Copyright © 2017 10yun.com | 十云提供计算服务-IPV6 | ctocode组开发