zoukankan      html  css  js  c++  java
  • 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 }) },
  • 相关阅读:
    reaver 破解wifi
    CDOJ 1255 斓少摘苹果 图论 2016_5_14
    CDOJ 1256 打表+数组 统计
    poj 3190 贪心+优先队列优化
    poj 2376 Cleaning Shifts 贪心 区间问题
    poj 3253 Fence Repair 贪心
    poj 3069 贪心+区间问题
    poj 3050 Hopscotch DFS+暴力搜索+set容器
    poj 2718 Smallest Difference(暴力搜索+STL+DFS)
    poj 3187 Backward Digit Sums
  • 原文地址:https://www.cnblogs.com/wuliujun521/p/11571276.html
Copyright © 2011-2022 走看看