tiny-vue/examples/sites/demos/pc/app/file-upload/prevent-delete-file.vue

39 lines
924 B
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<tiny-file-upload ref="upload" :action="action" :file-list="fileList" :before-remove="beforeRemove">
<template #trigger>
<tiny-button type="primary">选取文件</tiny-button>
</template>
</tiny-file-upload>
</template>
<script>
import { FileUpload, Button, Modal } from '@opentiny/vue'
export default {
components: {
TinyFileUpload: FileUpload,
TinyButton: Button
},
data() {
return {
action: 'http://localhost:3000/api/upload',
fileList: [
{
name: 'test1',
url: `${import.meta.env.VITE_APP_BUILD_BASE_URL}static/images/fruit.jpg`
}
]
}
},
methods: {
beforeRemove(file) {
return new Promise((resolve, reject) => {
Modal.confirm(`确定移除 ${file.name}`).then((res) => {
res === 'confirm' ? resolve() : reject(new Error('取消移除'))
})
})
}
}
}
</script>