screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h3>Vue Js File upload size limit validation</h3> <input type="file" @change="handleFileUpload"> <p v-if="fileSizeExceeded">File size exceeded the limit of {{ maxFileSize / 1000 }} KB</p> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { maxFileSize: 5000, // 5Kb fileSizeExceeded: false }; }, methods: { handleFileUpload(event) { const file = event.target.files[0]; if (file.size > this.maxFileSize) { this.fileSizeExceeded = true; return; // do not process the file if it exceeds the size limit } const reader = new FileReader(); reader.onloadend = () => { this.fileSizeExceeded = false; // do something with the file }; reader.readAsArrayBuffer(file); } } }); </script> <style scoped> #app { margin: 20px; padding: 20px; border: 1px solid #ccc; } h3 { font-size: 24px; font-weight: bold; margin-bottom: 10px; } input[type="file"] { margin-bottom: 10px; } p { font-size: 16px; color: red; margin-top: 10px; } </style> </body> </html>