screen_rotation
Copied to Clipboard
<html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h3>Vue Js Check if Input is Empty</h3> <label for="myInput">Enter something:</label> <input type="text" id="myInput" v-model="inputValue"> <button @click="submitForm">Submit</button> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { inputValue: '', }; }, methods: { submitForm() { if (!this.inputValue) { alert('Input field is empty!'); return; } // Do something with the input value console.log(this.inputValue); }, }, }); </script> <style scoped> #app { display: flex; flex-direction: column; align-items: center; } label { font-size: 1.2rem; margin-bottom: 0.5rem; } input[type="text"] { padding: 0.5rem; border-radius: 4px; border: 1px solid #ccc; font-size: 1rem; width: 100%; max-width: 400px; } button { background-color: #007bff; color: #fff; border-radius: 4px; border: none; padding: 0.5rem 1rem; font-size: 1rem; cursor: pointer; margin-top: 1rem; } button:hover { background-color: #0069d9; } </style> </body> </html>