Home  >  Article  >  Web Front-end  >  Detailed explanation of the steps to implement image and file upload in Vue

Detailed explanation of the steps to implement image and file upload in Vue

php中世界最好的语言
php中世界最好的语言Original
2018-05-10 15:56:059548browse

This time I will bring you a detailed explanation of the steps of Vue implementation of image and file upload. What are the precautions for Vue implementation of image and file upload? . The following is a practical case. Let’s take a look. one time.

html page

//注意不能带括号

js code

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',//这里是后台接口需要换掉
        type: 'POST',
        dataType: 'json',
        cache: false,
        data: formData,
        processData: false,
        contentType: false,
        success: (res) => {        
          if (res.code === 200) {
            var img_tpl ='

删除

';             $("#refund_img").after(img_tpl);           }         },         error: function(err) {         alert("网络错误");         }       }); }  }

Picture renderings

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website !

Recommended reading:

Detailed explanation of the steps of using axios in vue

Detailed explanation of the steps of axios post method to submit formdata

The above is the detailed content of Detailed explanation of the steps to implement image and file upload in Vue. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn