成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術(shù)文章
文章詳情頁

vue中element 的upload組件發(fā)送請求給后端操作

瀏覽:86日期:2022-11-28 09:25:06

1.用到了before-upload屬性,

用于在上傳文件前的校驗(yàn),并且發(fā)送請求給后端,傳輸格式進(jìn)行文件流傳輸

什么都不用設(shè)置,action屬性隨便設(shè)置,不能為空即可!

在before-upload屬性的方法中的代碼如下:

var _this = this; debugger; // var files=file.target.files[0]; debugger; const isJPG = file.type === 'image/jpeg'; const isLt2M = file.size / 1024 / 1024 < 2; if (!isJPG) { this.$message.error('上傳頭像圖片只能是 JPG 格式!'); } if (!isLt2M) { this.$message.error('上傳頭像圖片大小不能超過 2MB!'); } // return isJPG && isLt2M; let formData = new FormData(); formData.append('file', file); axios .post('http://192.168.0.116:8083/pic/upload', formData) .then(function(response) { _this.enclosure.openPermitimgUrl = response.data; // alert(response.data); console.log(response); }) .catch(function(error) { alert('上傳失敗'); console.log(error); });

補(bǔ)充知識:vue element 實(shí)現(xiàn)上傳導(dǎo)入功能(請求到后臺接口)

1、主要用到了element中upload的onSuccess方法

action后面跟著的是上傳文件后要被導(dǎo)入的接口

data是我們可能上傳多個 定義一個數(shù)組

vue中element 的upload組件發(fā)送請求給后端操作

2、在data中定義 uploadBase:{}

3、請求后臺的導(dǎo)入接口 傳給后臺所需要的參數(shù)

vue中element 的upload組件發(fā)送請求給后端操作

以上這篇vue中element 的upload組件發(fā)送請求給后端操作就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Vue
相關(guān)文章: