1.使用iview中的upload組件,選擇好文件后,點擊“上傳”按鈕才開始上傳2.iview的upload api文檔有說明,before-upload 上傳文件之前的鉤子,參數為上傳的文件,若返回 false 或者 Promise 則停止上傳所以我的想法是,通過before-upload回調函數中返回一個promise對象,點擊上傳后,執行promise的resolve方法,這樣就可以實現點擊后上傳目前的問題是,點擊“上傳”按鈕,如何執行Promise的resolve方法,vue中如何實現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); }},
iview中如何實現,點擊按鈕后開始上傳附件
牛魔王的故事
2019-03-13 13:11:21