How to implement it in iview? click the button and start uploading attachments.

1. Use the upload component in iview. After selecting the file, click the upload button to start uploading the upload api document of
2.iview.

the hook before before-upload uploads the file. The parameter is the uploaded file. If false or Promise is returned, the upload will be stopped

so my idea is to return a promise object in the before-upload callback function. After clicking upload, execute the resolve method of promise, so that you can upload after clicking.

< H2 > the current problem is, click the "upload" button, how to execute the resolve method of Promise, and how to implement it in vue < / H2 >.
upload(rawFile, file) {
  this.$refs.input.value = null;
  if (!this.beforeUpload) {
    return this.post(rawFile);
  }
  const before = this.beforeUpload(rawFile);
  if (before && before.then) {
    before.then(processedFile => {
      if (Object.prototype.toString.call(processedFile) === "[object File]") {
        this.post(processedFile);
      } else {
        this.post(rawFile);
      }
    }, () => {
      this.onRemove(null, rawFile);
    });
  } else if (before !== false) {
    this.post(rawFile);
  } else {
    this.onRemove(null, rawFile);
  }
},

https://github.com/oyv1cent/i.

is not based on promise, but you can refer to

.

you can store the returned promise in a data and pass it to the button click event through the click parameter.

Menu