Skip to content

上传业务组件

单个图片

附件上传
单个图片
<template>
  <su-upload class="vp-raw" ref="upload" isImg @change="change" :uploadUrl="fileUrl" />
</template>

<script setup lang="ts">
import axios from "axios";
import { ref } from 'vue'
const fileUrl = ref('');
const upload = ref();
const change = async (uploadData: FormData) => {
  let url = `${window.location.hostname === 'localhost' ? '/api':'http://192.168.0.176/node'}/file/upload`
  axios.post(url, uploadData).then((response) => {
    fileUrl.value = `http://192.168.0.176/${response.data.data.fileUrl}`;
    upload.value.update(fileUrl.value);
  });
};
</script>

单个文件

附件上传
单个文件
<template>
  <su-upload
    class="vp-raw"
    ref="upload"
    @change="change"
    :uploadUrl="fileUrl"
    :fileType="[
      'text/plain',
      'application/vnd.openxmlformats-officedocument.presentationml.presentation',
      'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      'application/pdf',
      'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
    ]"
  />
</template>

<script setup lang="ts">
import axios from "axios";
import { ref } from "vue";
const fileUrl = ref("");
const upload = ref();
const change = async (uploadData: FormData) => {
  let url = `${
    window.location.hostname === "localhost"
      ? "/api"
      : "http://192.168.0.176/node"
  }/file/upload`;
  axios.post(url, uploadData).then((response) => {
    fileUrl.value = `http://192.168.0.176/${response.data.data.fileUrl}`;
    upload.value.update(fileUrl.value);
  });
};
</script>

多个图片、文件混合上传

混合上传
<template>
  <su-upload
    class="vp-raw"
    ref="upload"
    :maxCount="3"
    @change="change"
    :uploadUrl="fileUrl"
    :fileType="[
      'image/apng',
      'image/bmp',
      'image/gif',
      'image/jpeg',
      'image/pjpeg',
      'image/png',
      'image/svg+xml',
      'image/tiff',
      'image/webp',
      'image/x-icon',
      'text/plain',
      'application/vnd.openxmlformats-officedocument.presentationml.presentation',
      'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      'application/pdf',
      'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
    ]"
  />
</template>

<script setup lang="ts">
import axios from "axios";
import { ref } from "vue";
const fileUrl = ref([]);
const upload = ref();
const change = async (uploadData: FormData) => {
  let url = `${
    window.location.hostname === "localhost"
      ? "/api"
      : "http://192.168.0.176/node"
  }/file/upload`;
  axios.post(url, uploadData).then((response) => {
    upload.value.update(`http://192.168.0.176/${response.data.data.fileUrl}`);
  });
};
</script>

组件参数配置

参数

说明

类型

默认值

uploadUrl图片地址string、string[]单页面存在有多个table并都开启showTools时配置
fileSize大小限制number默认为 5M
fileType类型限制FileTypes[]默认为 ["image/jpeg", "image/png", "image/gif"]
height组件高度string默认为 160px
width组件宽度string默认为 160px
borderRadius组件边框圆角string默认为 8px
maxCount最大上传数量number默认为1
uploadText显示文字string--
isImg是否只为图片, 用于单个图片上传boolean--

组件内暴露的值或方法

参数

说明

类型

示例

uploadFileList当前文件类别file[]--
update更新上传的文件function--