vue3-ElementPlus上传文件【代码】

<template>
  <el-upload ref="upload" :auto-upload="false" accept="" :show-file-list='false' :on-change="handleChangeUpload"
    action="#" class="upload-demo" multiple>
    <el-button type="primary">Click to uploadel-button>
  el-upload>
template>

<script setup>
import { onMounted, onUnmounted, reactive, toRefs, watch, onActivated } from 'vue'
// import { fileUpload } from '@/api/grid/common'
function handleChangeUpload(file) {
  let formData = new FormData()
  formData.append('文件', file.raw)
  fileUpload(formData).then(res => {//fileUpload换成你自己接口
    if (res.code == '200') {
      ElMessage({
        type: 'success',
        message: '上传成功',
      })
    } else {
      ElMessage.error(res.message)
    }
    // console.log(res);
  }).finally()
}
script>

你可能感兴趣的:(Vue,javascript,前端,vue.js)