2021-12-21 09:27:52 +08:00
|
|
|
<template>
|
|
|
|
<el-upload
|
|
|
|
ref="upload"
|
|
|
|
class="upload-demo"
|
|
|
|
action="https://jsonplaceholder.typicode.com/posts/"
|
|
|
|
:limit="1"
|
|
|
|
:on-exceed="handleExceed"
|
|
|
|
:auto-upload="false"
|
|
|
|
>
|
|
|
|
<template #trigger>
|
2021-12-28 19:38:23 +08:00
|
|
|
<el-button type="primary">select file</el-button>
|
2021-12-21 09:27:52 +08:00
|
|
|
</template>
|
2021-12-28 19:38:23 +08:00
|
|
|
<el-button class="ml-3" type="success" @click="submitUpload"
|
2021-12-21 09:27:52 +08:00
|
|
|
>upload to server</el-button
|
|
|
|
>
|
|
|
|
<template #tip>
|
|
|
|
<div class="el-upload__tip" style="color: red">
|
|
|
|
limit 1 file, new file will cover the old file
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</el-upload>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { ref } from 'vue'
|
|
|
|
const upload = ref()
|
|
|
|
|
|
|
|
const handleExceed = (files) => {
|
|
|
|
upload.value.clearFiles()
|
|
|
|
upload.value.handleStart(files[0])
|
|
|
|
}
|
|
|
|
const submitUpload = () => {
|
|
|
|
upload.value.submit()
|
|
|
|
}
|
|
|
|
</script>
|