Vue使用axios上传文件

<template>
  <div class="upload-demo">
    <input type="file" ref="fileInt" @change="changeHandle">
  </div>
</template>
 
<script>
 
export default {
  name: ‘UploadFileDemo‘,
  props: {
    msg: String
  },
  methods: {
    changeHandle() {
      const file = this.$refs.fileInt.files[0];
      console.log(file);
      const data = new FormData();
      data.append(‘file‘, file);
      axios.post(‘http://localhost:3006/common/upload‘, data, {
        headers: {
          ‘Content-Type‘: ‘multipart/form-data‘,
        },
      }).then(res => {
        console.log(res);
      }).catch(err => {
        console.log(err);
      });
    }
  },
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>

 

Vue使用axios上传文件

上一篇:Linux /proc目录详解


下一篇:Appium.01——环境搭建