Vue.js项目中使用 Ajax 和 FormDate 对象上传文件

let param = new FormData();

param.append("paths", this.ruleForm.uploadPath);

param.append("pkg", this.ruleForm.packageName);

//      param.append("file", $('#file')[0].files[0]);

 

this.$http({

  method: 'post',

  url: 'http://upload.com/doapi',

  data: param

}).then(res => {

  res = res.data;

  if(res.errorcode === 0) {

//  console.log(res)

    this.$message({

      message: res.msg,

      type: 'success'

    })

  } else {

    this.$message({

      message: res.msg,

      type: 'error'

    })

  }

});

posted @ 2018-03-27 09:58  heroljy  阅读(2404)  评论(0编辑  收藏  举报