Fxiaoke Developer Manual Fxiaoke Developer Manual
  • APL Development Manual
  • PWC Development Manual
  • OpenAPI Documentation
  • Custom Components (PC)
  • Custom Components (Mini Program)
  • Custom Plugins (PC)
  • Custom Plugins (Mini Program)
  • Third-party Integration Plugins (H5)
  • API (PC)
  • API (Mini Program)
  • Fx DevTools
Update Log
  • 简体中文
  • English
  • Custom Components (PC)
  • Custom Components (Mini Program)
  • Custom Plugins (PC)
  • Custom Plugins (Mini Program)
  • Third-party Integration Plugins (H5)
  • API (PC)
  • API (Mini Program)
  • Fx DevTools
Update Log
  • 简体中文
  • English
  • Getting Started

  • Components

    • Component Overview
    • UI Components

      • Button
      • Radio
      • Checkbox
      • Input
      • Input Number
      • Select
      • Cascader
      • Switch
      • Time Picker
      • Date Picker
      • DateTime Picker
      • Upload
        • Color Picker
        • Table
        • Tag
        • Progress
        • Tree
        • Pagination
        • Badge
        • Alert
        • Message
        • MessageBox
        • Notification
        • Dropdown
        • Steps
        • Dialog
        • Card
        • Calendar
        • Tooltip
        • Popover
        • Collapse
        • Carousel
      • Business Components

    • Examples

    • FAQ

    Table of Contents

    Upload

    # FxUpload Upload

    Upload files by clicking or dragging

    # Click to Upload

    Click to upload
    Only jpg/png files can be uploaded, and no more than 10000kb

    You can pass custom upload button type and text prompt through slot. You can limit the number of uploaded files and define the behavior when the limit is exceeded by setting limit and on-exceed. You can prevent file removal operations by setting before-remove.

    <fx-upload
      class="upload-demo"
      :accept="accept"
      :max-size="maxSize"
      :multiple="multiple"
      :limit="limit"
      :name="name"
      :file-list="fileList"
      :show-file-list="false"
      :on-preview="handlePreview"
      :on-remove="handleRemove"
      :on-success="handleSuccess"
      :on-error="handleError"
      :on-progress="handleProgress"
      :on-change="handleChange"
      :before-remove="beforeRemove"
      :on-exceed="handleExceed"
    >
      <fx-button size="small" type="primary">Click to upload</fx-button>
      <div slot="tip" class="el-upload__tip" v-if="maxSize">Only jpg/png files can be uploaded, and no more than {{maxSize}}kb</div>
      <!-- <div slot="file" slot-scope="{file}">
        <i class="el-icon-edit"></i>
      </div> -->
    </fx-upload>
    
    <!-- <fx-button @click="click">button</fx-button> -->
    
    <script>
      export default {
        data() {
          return {
            fileList:[],
            fileList0: [{ name: 'food.jpeg',size:1000, url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100' },{ name: 'food.jpeg',status:'uploading',percentage:'50', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100' }],
            multiple: true,
            limit: 2,
            name:'test',
            maxSize:10000,
            accept:'.png,.jpg'
          };
        },
        methods: {
          handleSuccess(response, file, fileList) {
            console.log('handleSuccess', response, file, fileList);
          },
          handleError(err, file, fileList) {
            console.log('handleError', err, file, fileList);
          },
          handleProgress(event, file, fileList) {
            console.log('handleProgress', event, file, fileList);
          },
          handleChange(file, fileList) {
            console.log('handleChange', file, fileList,this.fileList);
          },
          handlePreview(file) {
            console.log('handlePreview', file);
          },
          handleRemove(file, fileList) {
            console.log('handleRemove', file, fileList);
          },
          beforeRemove(file, fileList) {
            console.log('beforeRemove', file, fileList);
            console.log(this.fileList);
          },
          handleExceed(file, fileList, msg) {
            console.log('handleExceed', file, fileList, msg);
          },
          beforeUpload(){
            return false;
          },
          file() {
            console.log(arguments);
          },
          remove() {
            console.log(arguments);
          },
        },
      };
    </script>
    
    Expand Copy Copy

    # Avatar Upload

    Use before-upload to limit the image format and size uploaded by users.

    Only image files can be uploaded, and no more than 20kb
    <fx-upload
      class="avatar-uploader"
      :max-size="maxSize"
      :show-file-list="showFileList"
      :on-success="handleAvatarSuccess"
      :on-error="handleAvatarError"
      :before-upload="beforeAvatarUpload"
    >
      <img v-if="imageUrl" :src="imageUrl" class="avatar" />
      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      <div slot="tip" class="el-upload__tip" v-if="maxSize">Only image files can be uploaded, and no more than {{maxSize}}kb</div>
    </fx-upload>
    
    <script>
      export default {
        data() {
          return {
            imageUrl: '',
            showFileList:false,
            maxSize:20
          };
        },
        methods: {
          handleAvatarSuccess(res, file) {
            console.log('handleAvatarSuccess...',res,file)
            this.imageUrl = URL.createObjectURL(file.raw);
          },
          handleAvatarError(err,file){
            console.log('handleAvatarError...',err,file)
            this.imageUrl = URL.createObjectURL(file.raw);
          },
          beforeAvatarUpload(files) {
            const file=files[0];
            const isJPG = file.type === 'image/jpeg';
            const isLt2M = file.size / 1024 / 1024 < 2;
    
            if (!isJPG) {
              this.$message.error('Avatar image can only be in JPG format!');
            }
            if (!isLt2M) {
              this.$message.error('Avatar image size cannot exceed 2MB!');
            }
            return isJPG && isLt2M;
          },
        },
      };
    </script>
    
    <style>
      .avatar-uploader .el-upload {
        border: 1px solid #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
      }
      .avatar-uploader .el-upload:hover {
        border-color: #409eff;
      }
      .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 70px;
        height: 70px;
        line-height: 70px;
        text-align: center;
      }
      .avatar {
        width: 70px;
        height: 70px;
        display: block;
      }
    </style>
    
    Expand Copy Copy

    # Photo Wall

    Use the list-type attribute to set the style of the file list.

    <fx-upload
      url="https://jsonplaceholder.typicode.com/posts/"
      list-type="picture-card"
      :on-preview="handlePictureCardPreview"
      :on-remove="handleRemove">
      <i class="el-icon-plus"></i>
    </fx-upload>
    <fx-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="">
    </fx-dialog>
    <script>
      export default {
        data() {
          return {
            dialogImageUrl: '',
            dialogVisible: false
          };
        },
        methods: {
          handleRemove(file, fileList) {
            console.log(file, fileList);
          },
          handlePictureCardPreview(file) {
            this.dialogImageUrl = file.url;
            this.dialogVisible = true;
          }
        }
      }
    </script>
    
    
    Expand Copy Copy

    # File Thumbnail

    Use scoped-slot to set the thumbnail template.

    <fx-upload
      url="#"
      list-type="picture-card"
      :auto-upload="false">
        <i slot="default" class="el-icon-plus"></i>
        <div slot="file" slot-scope="{file}">
          <img
            class="el-upload-list__item-thumbnail"
            :src="file.url" alt=""
          >
          <span class="el-upload-list__item-actions">
            <span
              class="el-upload-list__item-preview"
              @click="handlePictureCardPreview(file)"
            >
              <i class="el-icon-zoom-in"></i>
            </span>
            <span
              v-if="!disabled"
              class="el-upload-list__item-delete"
              @click="handleRemove(file)"
            >
              <i class="el-icon-delete"></i>
            </span>
          </span>
        </div>
    </fx-upload>
    <fx-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="">
    </fx-dialog>
    <script>
      export default {
        data() {
          return {
            dialogImageUrl: '',
            dialogVisible: false,
            disabled: false
          };
        },
        methods: {
          handleRemove(file) {
            console.log(file);
          },
          handlePictureCardPreview(file) {
            this.dialogImageUrl = file.url;
            this.dialogVisible = true;
          },
          handleDownload(file) {
            console.log(file);
          }
        }
      }
    </script>
    
    Expand Copy Copy

    # Image List Thumbnail

    Click to upload
    Only jpg/png files can be uploaded, and no more than 500kb
    <fx-upload
      class="upload-demo"
      url="https://jsonplaceholder.typicode.com/posts/"
      :on-preview="handlePreview"
      :on-remove="handleRemove"
      :file-list="fileList"
      list-type="picture">
      <fx-button size="small" type="primary">Click to upload</fx-button>
      <div slot="tip" class="el-upload__tip">Only jpg/png files can be uploaded, and no more than 500kb</div>
    </fx-upload>
    <script>
      export default {
        data() {
          return {
            fileList: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}]
          };
        },
        methods: {
          handleRemove(file, fileList) {
            console.log(file, fileList);
          },
          handlePreview(file) {
            console.log(file);
          }
        }
      }
    </script>
    
    Expand Copy Copy

    # Upload File List Control

    Control the list through the on-change hook function

    Click to upload
    Only jpg/png files can be uploaded, and no more than 500kb
    <fx-upload
      class="upload-demo"
      url="https://jsonplaceholder.typicode.com/posts/"
      :on-change="handleChange"
      :show-file-list="false"
      :file-list="fileList">
      <fx-button size="small" type="primary">Click to upload</fx-button>
      <div slot="tip" class="el-upload__tip">Only jpg/png files can be uploaded, and no more than 500kb</div>
    </fx-upload>
    <script>
      export default {
        data() {
          return {
            fileList: [{
              name: 'food.jpeg',
              url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'
            }, {
              name: 'food2.jpeg',
              url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'
            }]
          };
        },
        methods: {
          handleChange(file, fileList) {
            this.fileList = fileList.slice(-3);
          }
        }
      }
    </script>
    
    Expand Copy Copy

    # Drag to Upload

    Drag file here, or click to upload
    Only jpg/png files can be uploaded, and no more than 500kb
    <fx-upload
      class="upload-demo"
      drag
      :show-file-list="false"
      url="https://jsonplaceholder.typicode.com/posts/"
      multiple>
      <i class="el-icon-upload"></i>
      <div class="el-upload__text">Drag file here, or <em>click to upload</em></div>
      <div class="el-upload__tip" slot="tip">Only jpg/png files can be uploaded, and no more than 500kb</div>
    </fx-upload>
    
    
    Expand Copy Copy

    # Manual Upload

    Select File Upload to Server
    Only jpg/png files can be uploaded, and no more than 500kb
    <fx-upload
      class="upload-demo"
      ref="upload"
      url="https://jsonplaceholder.typicode.com/posts/"
      :on-preview="handlePreview"
      :on-remove="handleRemove"
      :file-list="fileList"
      :show-file-list="false"
      :auto-upload="false">
      <fx-button slot="trigger" size="small" type="primary">Select File</fx-button>
      <fx-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">Upload to Server</fx-button>
      <div slot="tip" class="el-upload__tip">Only jpg/png files can be uploaded, and no more than 500kb</div>
    </fx-upload>
    <script>
      export default {
        data() {
          return {
            fileList: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}]
          };
        },
        methods: {
          submitUpload() {
            this.$refs.upload.submit();
          },
          handleRemove(file, fileList) {
            console.log(file, fileList);
          },
          handlePreview(file) {
            console.log(file);
          }
        }
      }
    </script>
    
    Expand Copy Copy

    # Chunk Upload

    Click to upload
    Only jpg/png files can be uploaded, and no more than 500kb
    <fx-upload 
      ref="el" 
      multiple
      :url="url"
      :when-chunks="whenChunks"
      :chunk="chunk"
      :on-progress="onProgress"
      :on-success="onSuccess"
      :on-error="onError"
      :show-file-list="false"
      :on-exceed="onExceed">
      <fx-button size="small" type="primary">Click to upload</fx-button>
      <div slot="tip" class="el-upload__tip">Only jpg/png files can be uploaded, and no more than 500kb</div>
    </fx-upload>
    
    <script>
      export default {
        data(){
          return {
            url:'/mock/uploading.json',
            whenChunks:10240,//10k
            chunk:{
              mime: "multipart/form-data",
              size: 5120,
              tryTime: 1,
              starturl: "/mock/uploadstart.json",
              uploadurl: "/mock/uploading.json",
              doneurl: "/mock/uploadend.json"
            }
          }
        },
        methods:{
          onExceed(){
            console.log('upload_onExceed',arguments);
          },
          onProgress(){
            console.log('upload_onProgress',arguments);
          },
          onSuccess(){
            console.log('upload_onSuccess',arguments);
          },
          onError(){
            console.log('upload_onError',arguments);
          },
          onEnd(){
            console.log('upload_onEnd',arguments);
          }
        }
      };
    </script>
    
    Expand Copy Copy

    Attributes

    Attribute Description Type Options Default
    url File upload address (non-chunk) string — "/FSC/EM/File/UploadByForm"
    headers Set the request headers for upload object — —
    multiple Whether to support multiple file selection boolean — —
    data Additional parameters attached when uploading object — —
    name Field name of the uploaded file string — file
    with-credentials Support sending cookie credential information boolean — false
    show-file-list Whether to display the uploaded file list boolean — true
    drag Whether to enable drag and drop upload boolean — false
    accept Accepted file types for upload (this parameter is invalid in thumbnail-mode), multiple types separated by commas string .txt,.pdf,.jpg —
    on-preview Hook function when clicking on uploaded files in the file list function(file) — —
    on-remove Hook function when removing files from the file list function(file, fileList) — —
    on-success Hook function when file upload succeeds function(response, file, fileList) — —
    on-error Hook function when file upload fails function(err, file, fileList) — —
    on-progress Hook function during file upload function(event, file, fileList) — —
    on-change Hook function when file status changes, called when adding files, upload succeeds, and upload fails function(file, fileList) — —
    on-exceed Hook function when files exceed the limit function(files, fileList,o)
    files: newly selected files
    o.type:
    1: number of files exceeds limit (limit must be set),
    2: file size exceeds limit (maxSize must be set)
    3: file type does not match (accept must be set)
    — —
    before-upload Hook function before uploading files, parameter is the file to be uploaded. If false is returned, upload will be stopped. function(files) — —
    before-remove Hook function before removing files, parameters are the file to be removed and the file list. If false is returned or a Promise is returned and rejected, removal will be stopped. function(file, fileList) — —
    list-type Type of file list string text/picture/picture-card text
    auto-upload Whether to upload immediately after selecting files boolean — true
    file-list List of uploaded files, e.g.: [{name: 'food.jpg', url: 'https://xxx.cdn.com/xxx.jpg'}] array — []
    http-request Override the default upload behavior, can customize the upload implementation function(options) — —
    disabled Whether to disable boolean — false
    limit Maximum number of files allowed to upload number — —
    max-size Maximum upload size allowed (KB), default 10M number — 10485760
    basePath Root address of upload interface string — —
    whenChunks When file size exceeds this value, chunk upload will be used, default 0: no chunking, unit B number — 0
    chunk Chunk information, see chunk table below object — —

    chunk

    Attribute Description Type Options Default
    mime Value of Content-Type in the request string — —
    size Chunk size, unit B number — 2097152
    tryTime Number of retries on failure number — 3
    starturl Upload preprocessing interface string — "/FSC/EM/File/ChunkFileUploadStart"
    uploadurl Chunk upload interface string — "/FSC/EM/File/ChunkFileUploadDataByStream"
    doneurl Post-upload processing interface string — "/FSC/EM/File/ChunkFileUploadComplete"

    Slot

    Name Description
    trigger Content that triggers the file selection box
    tip Tip text

    Methods

    Method Description Parameters
    clearFiles Clear the uploaded file list (this method cannot be called in before-upload) —
    getFiles Get the uploaded file list —
    abort Cancel upload request ( file: file object in fileList )
    uploadFile Manually upload file(s), can be used for re-upload file
    DateTime Picker
    Color Picker

    ← DateTime Picker Color Picker→

    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式