element-ui自定义上传图片

:http-request="uploadFile"其中uploadFile就可以是自定义的方法,具体如下:


                        选取文件
            uploadFile(param) {
                console.log( param.file);
                console.log(param.file.name);
                let uploadData = new FormData();
                uploadData.append('file', param.file);
                let config = {
                    headers: {
                        'Content-Type': 'multipart/form-data'
                    }
                }
                uploadImg(uploadData,config).then(data => {
                    if (data.status != 0) {
                        this.$alert(data.message);
                    } else {
                        console.log(data);
                        
                    }
                });
            },
export const uploadImg = (params,config) => { return axios.post(`${base}/csb/uploadImg`, params,config).then(res => res.data); };

 

你可能感兴趣的:(教程)