axios不用封装单独上传图片文件

<input  name="file" type="file" accept="image/png,image/gif,image/jpeg" @change="update"/>
import axios from 'axios'

     // 添加请求头
update (e) {   // 上传照片
      var self = this
      let file = e.target.files[0]
      /* eslint-disable no-undef */
      let param = new FormData()  // 创建form对象
      param.append('file', file, file.name)  // 通过append向form对象添加数据
      param.append('chunk', '0') // 添加form表单中其他数据
      console.log(param.get('file')) // FormData私有类对象,访问不到,可以通过get判断值是否传进去
      let config = {
        headers: {'Content-Type': 'multipart/form-data'}
      }
     // 添加请求头
    axios.post('http://172.19.26.60:8081/rest/user/headurl', param, config)
        .then(response => {
          if (response.data.code === 0) {
         

相关推荐

  1. axios封装单独图片文件

    2023-12-15 12:14:04       50 阅读
  2. flutter 文件封装

    2023-12-15 12:14:04       54 阅读
  3. element-ui图片组件封装

    2023-12-15 12:14:04       40 阅读
  4. Axios 中的文件(Upload File)方法

    2023-12-15 12:14:04       46 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-15 12:14:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-15 12:14:04       101 阅读
  3. 在Django里面运行非项目文件

    2023-12-15 12:14:04       82 阅读
  4. Python语言-面向对象

    2023-12-15 12:14:04       91 阅读

热门阅读

  1. redis的hash实现

    2023-12-15 12:14:04       60 阅读
  2. android常用

    2023-12-15 12:14:04       48 阅读
  3. Vue 循环渲染 v-for

    2023-12-15 12:14:04       53 阅读
  4. OSS上传pdf无法解析的问题

    2023-12-15 12:14:04       52 阅读
  5. Python 自动化之处理图片(一)

    2023-12-15 12:14:04       52 阅读
  6. Leetcode724.寻找数组中心下标(通俗易懂版)

    2023-12-15 12:14:04       54 阅读
  7. RocketMQ的架构是什么样的❓

    2023-12-15 12:14:04       66 阅读
  8. LeetCode-232. 用栈实现队列【栈 设计 队列】

    2023-12-15 12:14:04       46 阅读
  9. ARM开发

    ARM开发

    2023-12-15 12:14:04      65 阅读
  10. dapper使用Insert或update时部分字段不映射到数据库

    2023-12-15 12:14:04       58 阅读