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 Check if Input File is Empty</h3> <input type="file" ref="fileInput" @change="checkFile" /> <p v-if="isFileEmpty" class="empty">File is empty</p> <p v-else class="not-empty">Selected file: {{ selectedFileName }}</p> </div> <script> const app = new Vue({ el: "#app", data() { return { isFileEmpty: true, selectedFileName: "" }; }, methods: { checkFile() { // Access the input element const fileInput = this.$refs.fileInput; // Check if files are selected if (fileInput.files.length > 0) { this.isFileEmpty = false; this.selectedFileName = fileInput.files[0].name; // Display the selected file name } else { this.isFileEmpty = true; this.selectedFileName = ""; } } } }); </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[type="file"] { margin-top: 10px; } p { margin-top: 10px; font-weight: bold; } p.empty { color: red; /* You can customize the color for an empty file message */ } p.not-empty { color: green; /* You can customize the color for a non-empty file message */ } </style> </body> </html>