<template>
  <div>
    <input type="file" ref="fileInput" @change="handleFileChange">
    <button @click="uploadFile">上传文件</button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      file: null
    };
  },
  methods: {
    handleFileChange(event) {
      this.file = event.target.files[0];
    },
    uploadFile() {
      const formData = new FormData();
      formData.append("file", this.file);
      axios.post("/api/upload", formData).then(response => {
        console.log(response.data);
      });
    }
  }
};
</script>
写一段vue文件上传代码

原文地址: https://www.cveoy.top/t/topic/b59D 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录