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

vue中實(shí)現(xiàn)圖片和文件上傳的示例代碼

 更新時(shí)間:2018年03月16日 09:49:55   投稿:jingxian  
下面小編就為大家分享一篇在vue中實(shí)現(xiàn)圖片和文件上傳的示例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

html頁面

<input type="file" value="" id="file" @change='onUpload'>//注意不能帶括號(hào)

js代碼

methods: {
//上傳圖片
onUpload(e){
      var formData = new FormData(); 
    f ormData.append('file', e.target.files[0]);
    formData.append('type', 'test');
      $.ajax({
        url: '/ShopApi/util/upload.weixun',//這里是后臺(tái)接口需要換掉
        type: 'POST',
        dataType: 'json',
        cache: false,
        data: formData,
        processData: false,
        contentType: false,
        success: (res) => {        
          if (res.code === 200) {
            var img_tpl ='<div class="picture" style="width:108px;float:left;"><img id="preview" src="'+后臺(tái)返回的tu'pian路徑+'" style="width:48px;height:48px;float:left;background-size:cover;"/><span class="r-span"
 onclick = "onDeletePicture()" style="color:#49BDCC;display:block;float:left;margin-left:10px;line-height:48px;">刪除</span></div>';
            $("#refund_img").after(img_tpl);
          }
        },
        error: function(err) {
        alert("網(wǎng)絡(luò)錯(cuò)誤");
        }
      });
} 
}

圖片效果圖

以上這篇vue中實(shí)現(xiàn)圖片和文件上傳的示例代碼就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論