首页 > 移动平台 > 详细

Vue使用axios上传文件

时间:2019-04-27 13:00:48      阅读:299      评论:0      收藏:0      [点我收藏+]
<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上传文件

原文:https://www.cnblogs.com/Narkea/p/10778255.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!