el-upload 修改默认上传行为,传递参数

<el-upload action="url" :data="{type:type}" :http-request="uploadFile">
  
  <el-button>上传</el-button>

</el-upload>
<script>
  export default{
  data(){
    return {
      type:'1'
  }
}
  methods:{
    // 上传
    handleUploadFile(param){
      const formData=new FormData();
      formData.append('file',param.file)
      formData.append('file',param.data.type)
      uploadFileApi(formData)
        .then(res=>{
          console.log('上传成功')
      })
        .catch(res=>{
          console.log('上传失败')
      })
    }
  } }
</script>
export function uploadFileApi(data){
  return request({
       url:'url',
    method:'post',
    data:data }) }

 

posted @ 2022-09-28 15:30  island_0  阅读(892)  评论(0编辑  收藏  举报