primevue-mirror/apps/showcase/doc/fileupload/CustomUploadDoc.vue

94 lines
2.7 KiB
Vue
Raw Permalink Normal View History

2023-02-28 08:29:30 +00:00
<template>
<DocSectionText v-bind="$attrs">
2024-08-29 21:43:40 +00:00
<p>Uploading implementation can be overridden by enabling <i>customUpload</i> property. This sample, displays the image on the client side with a grayscale filter.</p>
2023-02-28 08:29:30 +00:00
</DocSectionText>
2024-08-29 21:43:40 +00:00
<div class="card flex flex-col items-center gap-6">
<FileUpload mode="basic" @select="onFileSelect" customUpload auto severity="secondary" class="p-button-outlined" />
<img v-if="src" :src="src" alt="Image" class="shadow-md rounded-xl w-full sm:w-64" style="filter: grayscale(100%)" />
2023-02-28 08:29:30 +00:00
</div>
<DocSectionCode :code="code" />
</template>
<script>
export default {
data() {
return {
2024-08-29 21:43:40 +00:00
src: null,
2023-02-28 08:29:30 +00:00
code: {
2023-09-22 12:54:14 +00:00
basic: `
2024-08-29 21:43:40 +00:00
<FileUpload mode="basic" @select="onFileSelect" customUpload auto severity="secondary" class="p-button-outlined" />
<img v-if="src" :src="src" alt="Image" class="shadow-md rounded-xl w-full sm:w-64" style="filter: grayscale(100%)" />
2023-10-15 09:38:39 +00:00
`,
2023-09-22 12:54:14 +00:00
options: `
<template>
2024-08-29 21:43:40 +00:00
<div class="card flex flex-col items-center gap-6">
<FileUpload mode="basic" @select="onFileSelect" customUpload auto severity="secondary" class="p-button-outlined" />
<img v-if="src" :src="src" alt="Image" class="shadow-md rounded-xl w-full sm:w-64" style="filter: grayscale(100%)" />
2023-02-28 08:29:30 +00:00
</div>
</template>
<script>
export default {
2024-08-29 21:43:40 +00:00
data() {
return {
src: null
}
},
2023-02-28 08:29:30 +00:00
methods: {
2024-08-29 21:43:40 +00:00
onFileSelect(event) {
2023-02-28 08:29:30 +00:00
const file = event.files[0];
const reader = new FileReader();
2024-08-29 21:43:40 +00:00
reader.onload = async (e) => {
this.src = e.target.result;
2023-02-28 08:29:30 +00:00
};
2024-08-29 21:43:40 +00:00
reader.readAsDataURL(file);
2023-02-28 08:29:30 +00:00
}
}
};
2023-10-15 09:38:39 +00:00
<\/script>
`,
2023-09-22 12:54:14 +00:00
composition: `
<template>
2024-08-29 21:43:40 +00:00
<div class="card flex flex-col items-center gap-6">
<FileUpload mode="basic" @select="onFileSelect" customUpload auto severity="secondary" class="p-button-outlined" />
<img v-if="src" :src="src" alt="Image" class="shadow-md rounded-xl w-full sm:w-64" style="filter: grayscale(100%)" />
2023-02-28 08:29:30 +00:00
</div>
</template>
<script setup>
2024-08-29 21:43:40 +00:00
import { ref } from "vue";
const src = ref(null);
function onFileSelect(event) {
2023-02-28 08:29:30 +00:00
const file = event.files[0];
const reader = new FileReader();
2024-08-29 21:43:40 +00:00
reader.onload = async (e) => {
src.value = e.target.result;
2023-02-28 08:29:30 +00:00
};
2024-08-29 21:43:40 +00:00
reader.readAsDataURL(file);
}
2023-10-15 09:38:39 +00:00
<\/script>
`
2023-02-28 08:29:30 +00:00
}
};
},
methods: {
2024-08-29 21:43:40 +00:00
onFileSelect(event) {
2023-02-28 08:29:30 +00:00
const file = event.files[0];
const reader = new FileReader();
2024-08-29 21:43:40 +00:00
reader.onload = async (e) => {
this.src = e.target.result;
2023-02-28 08:29:30 +00:00
};
2024-08-29 21:43:40 +00:00
reader.readAsDataURL(file);
2023-02-28 08:29:30 +00:00
}
}
};
</script>