formData请求接口传递参数格式

element ui组件方法的传递

//引入 组件。
<el-upload
    class="avatar-uploader"
    :action="action"
    :http-request="uploadFile"
    :show-file-list="false">
    <img v-if="imageUrl" :src="imageUrl" class="avatar">
    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>

uploadFile(data){
        var userinfo = this.$baseMethod.getStore('_ccmUser')
        let formdata = new FormData();
        formdata.append('file',data.file);
        formdata.append('token',userinfo.token);
        formdata.append('op',"uploadChannelPic");
        formdata.append('data',JSON.stringify({}));
    uploadFile(formdata).then(res => {
        this.imageUrl = JSON.parse(res.data).picUrl
        // console.log(JSON.parse(res.data))
    })
},

这一段是js上传FormData请求格式

<input type="file"
 id="file"  
//设置上传格式化
accept="image/jpg,image/jpeg,image/png,image/gif"   
//获取上传内容
@change="fileUpload()" 
/>

fileUpload() {
  var f = document.getElementById('file').files[0];
  let formdata = new FormData()
  formdata.append('file',f);
  formdata.append('token',storage.get('loginToken'));
  formdata.append('op',"uploadChannelPic");   
    formdata.append('data',JSON.stringify({}));
//这里是请求接口进行传递formdata 
  this.$upload("/channel/perfection/uploadFile",formdata ).then(res => {
  //请求成功后赋值给要展示的图片
this.fileImg = JSON.parse(res.data).picUrl }) },

 

转载于:https://www.cnblogs.com/wuliujun521/p/11571276.html

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页