it-tools/tools/web/file-to-base64.vue

104 lines
2.5 KiB
Vue
Raw Normal View History

2021-03-14 21:20:35 +01:00
<template>
2021-05-28 19:44:27 +02:00
<ToolWrapper :config="$toolConfig" no-card="true">
2021-03-15 12:26:20 +01:00
<FileUploader v-model="file" />
2021-03-14 21:20:35 +01:00
<div v-if="base64 || loading" class="mt-10">
<v-card>
<v-card-title>Result</v-card-title>
<v-card-text>
<v-textarea
v-model="base64"
label="File in base 64"
outlined
readonly
hide-details
:loading="loading"
/>
<div class="text-center mt-4">
<v-btn depressed @click="copy(base64)">
Copy base64
</v-btn>
</div>
</v-card-text>
</v-card>
</div>
</ToolWrapper>
</template>
2021-05-28 19:44:27 +02:00
<tool>
title: 'File to base64'
description: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Delectus distinctio dolor dolorum eaque eligendi, facilis impedit laboriosam odit placeat.'
icon: 'mdi-file-link-outline'
keywords: ['file', 'base64']
path: '/file-to-base64'
</tool>
2021-03-14 21:20:35 +01:00
<script lang="ts">
import {Component, Watch} from 'nuxt-property-decorator'
import {CopyableMixin} from '@/mixins/copyable.mixin'
2021-03-14 23:37:57 +01:00
import Tool from '@/components/Tool.vue'
import FileUploader from '~/components/FileUploader.vue'
2021-03-14 21:20:35 +01:00
@Component({
mixins: [CopyableMixin],
components: {FileUploader}
})
export default class FileToBase64 extends Tool {
2021-03-14 23:37:57 +01:00
file: Blob | null = null
2021-03-14 21:20:35 +01:00
loading = false
2021-03-14 23:37:57 +01:00
base64 = ''
2021-03-14 21:20:35 +01:00
2021-03-14 23:37:57 +01:00
handleBase64(base64: string) {
2021-03-14 21:20:35 +01:00
this.base64 = base64
this.loading = false
}
@Watch('file')
onFile() {
2021-03-14 23:37:57 +01:00
if (this.file) {
this.loading = true
this.base64 = ''
const reader = new FileReader()
reader.onload = () => this.handleBase64(reader.result as string)
reader.onerror = () => this.handleBase64('[An error as occurred]')
reader.readAsDataURL(this.file)
}
2021-03-14 21:20:35 +01:00
}
}
// export default {
// name: 'FileToBase64',
// components: {FileUploader},
// data() {
// return {
// file: undefined,
// loading: false,
// base64: '',
// copyBase64() {
// copyToClipboard(this.base64)
// this.$toast.success('Copied to clipboard.')
// }
// }
// },
// watch: {
// file() {
// this.loading = true
// this.base64 = ''
// const reader = new FileReader()
// reader.onload = () => this.handleBase64(reader.result)
// reader.onerror = () => this.handleBase64('[An error as occurred]')
// reader.readAsDataURL(this.file)
// }
// },
// methods: {
// handleBase64(base64) {
// this.base64 = base64
// this.loading = false
// }
// }
// }
</script>
<style scoped>
</style>