xiaomili
文件下载:https://www.cnblogs.com/xiaomili/p/10521160.html 

html:

<form name="form1" id="form1">  
     <input type="text" name="name" value="fdipzone">  
     <input type="text" name="gender" value="male">  
     <input type="file" />文件上传
    <button type="button">上传文件</button>    
</form> 

js:

        /**
             * 文件上传
             */
            uploadFile(dom,upload,fn=false){
              const self = this;
              $(dom).on(\'change\',function(){
                let _index = $(this).index();// 表单索引0,1(多个表单)
                let fd = new FormData();// // FormData 对象
                let {length} = $(this).get(_index).files;

                if(length > 0){
                  for(let index of [...new Set($(this).get(_index).files)].keys()){
                    fd.append("file",  $(this).get(_index).files[index]);// 添加参数
                  }
                }

                let $http = self.$util.Ajax;
                let url = `${upload}`;// 上传地址
                let data = fd;

                $http.post(url, data, (res) => {// 自己包装的ajax
                  if (res.status == 0) {
                    self.$util.MessageUtil.info(\'上传成功!\');
                  }else{
                    self.$util.MessageUtil.error(\'上传失败!\');
                  }
                },\'json\',true,false);

              });
            },

 

分类:

技术点:

相关文章:

  • 2021-12-03
  • 2022-12-23
  • 2021-11-17
  • 2021-11-17
  • 2019-10-31
  • 2022-01-08
  • 2022-12-23
  • 2022-03-02
猜你喜欢
  • 2021-12-02
  • 2021-11-17
  • 2021-11-06
  • 2021-07-09
  • 2022-01-09
  • 2021-12-31
相关资源
相似解决方案