在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ vue大文件上傳組件選哪個好?

vue大文件上傳組件選哪個好?

vue支持大文件上傳的組件有好幾個,哪個比較成熟穩(wěn)定一點的?對后端的api有什么要求?后端用的是django-rest-framework

https://github.com/lian-yue/v...
https://github.com/FineUpload...
https://github.com/simple-upl...

回答
編輯回答
亮瞎她

我也一直找組件,但是后來,自己網(wǎng)上找了一個上傳方法,組件的話哪個交互好就選哪個,自己寫一個也行。代碼貼上:

 /*選擇上傳圖片切換 這個是methods里的,注意uploadImg*/
    onFileChange(e){
        var self=this;
        var fileInput=e.target;
        if(fileInput.files.length==0){
            return;
        }
        this.editor.focus();
        uploadImg(fileInput.files[0], "uploadimage" ,this.action, (result)=>{
            if(result.status == 'error') this.$message.error(result.msg);
            else {
                console.log(result);
                self.editor.insertEmbed(self.editor.getSelection().index, 'image', result.url);
            }
        });
    },

下面的是uploadImg方法,方便引入

```
/*@params :文件 input的名字 后端的上傳地址 上傳完畢后回調(diào)函數(shù)*/
export function uploadImg(file,inputName,action,cb) {
const isAllow = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif';
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isAllow) {
    cb({ "status" : 'error' , 'msg' : '上傳的圖片須是 JPG、PNG 或 GIF 格式' });
    return ;
}
if (!isLt2M) {
    cb({ "status" : 'error' , 'msg' : '上傳的圖片大小不能超過 2MB' });
    return ;
}
var data = new FormData;
let formData = new FormData();
formData.append(inputName, file);
let config = {
    headers: {'Content-Type': 'multipart/form-data'},
    params: {
        "action": "uploadimage",
        'filename': inputName
    }
};
axios.post( action , formData, config).then(function (res) {
    cb(res);
    return ;
});

}

2017年7月23日 12:36