欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2020年09月07日 11:29:57   作者:瘦瘦的小芝芝  
這篇文章主要介紹了vue中element 的upload組件發(fā)送請(qǐng)求給后端操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

1.用到了before-upload屬性,

用于在上傳文件前的校驗(yàn),并且發(fā)送請(qǐng)求給后端,傳輸格式進(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ǔ)充知識(shí):vue element 實(shí)現(xiàn)上傳導(dǎo)入功能(請(qǐng)求到后臺(tái)接口)

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

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

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

2、在data中定義 uploadBase:{}

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

以上這篇vue中element 的upload組件發(fā)送請(qǐng)求給后端操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論