我想要在上傳文件之前判斷這個資源屬性屬於哪種,如果不是正確的資源屬性那麼就終止上傳。
第一步:
首先before終止上傳按理來說直接return false 就可以了,但是直接寫並不管用,還是會去上傳,查了一下很多人都說改源碼:
找upload.js文件到下列代碼:
1
y = function() {
if ("choose" !== t && !l.auto || (l.choose && l.choose(g), "choose" !== t)) return l.before && l.before(g),
a.ie ? a.ie > 9 ? u() : c() : void u()
};
用下列代碼替換大括號中的代碼:
return "choose" === t ? l.choose && l.choose(g) : ((l.before && l.before(g)) === false ? '' : a.ie ? a.ie > 9 ? u() : c() : void u())
但是,我這邊實踐時,choose 回調失效了,項目需求需要 choose 後重新在自定義位置展示上傳文件名
解決辦法是 修改如下
y = function() {
if ("choose" !== t && !l.auto || (l.choose && l.choose(g), "choose" !== t)) return (l.before && l.before(g))===false?'':a.ie ? a.ie > 9 ? u() : c() : void u()
};
然後在 before 中相應邏輯中 return false 就行啦
參考文章:https://blog.csdn.net/qq_38529889/article/details/89242845