screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script> </head> <body> <div id="app"> <h3>Vue js Convert File Size to MB</h3> <input type="file" @change="handleFileInputChange" /> <p class="file-size">File Size in Bytes: {{ fileSizeInBytes }} bytes</p> <p class="file-size">File Size in MB: {{ fileSizeInMB.toFixed(2) }} MB</p> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { fileSizeInBytes: 0, fileSizeInMB: 0, }; }, methods: { handleFileInputChange(event) { const file = event.target.files[0]; if (file) { const fileSizeBytes = file.size; const fileSizeMB = fileSizeBytes / (1024 * 1024); // Convert to MB this.fileSizeInBytes = fileSizeBytes; this.fileSizeInMB = fileSizeMB; } else { this.fileSizeInBytes = 0; this.fileSizeInMB = 0; } }, }, }) </script> <style scoped> #app { margin: 0 auto; width: 500px; text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); padding: 20px; } input { padding: 10px; border: 2px dashed #ccc; border-radius: 5px; font-size: 16px; width: 200px; margin-top: 10px; } input:focus { outline: none; border-color: #007bff; } </style> </body> </html>