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