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 Submit Array</h3> <form @submit.prevent="submitArray"> <input v-model="newValue" type="text" placeholder="Enter a value"> <button type="submit">Submit</button> <p v-if="errorMessage" class="error-message">{{ errorMessage }}</p> </form> <ul v-if="myArray.length"> <li v-for="item in myArray" :key="item.id"> {{ item.id }}: {{ item.value }} </li> </ul> <p v-else>No items submitted yet.</p> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { myArray: [], newValue: '', nextId: 1, errorMessage: '' } }, methods: { submitArray() { if (this.newValue.trim() !== '') { this.myArray.push({ id: this.nextId++, value: this.newValue }); this.newValue = ''; this.errorMessage = ''; // Clear any previous error message } else { this.errorMessage = 'Invalid value. Please enter a non-empty value.'; } } } }); </script> <style scoped> #app { margin: 20px; font-family: Arial, sans-serif; } h3 { margin-bottom: 10px; color: #333; } form { margin-bottom: 10px; } input[type="text"] { padding: 10px; width: 250px; border: 1px solid #ccc; border-radius: 5px; font-size: 14px; } button[type="submit"] { padding: 10px 15px; background-color: #4caf50; color: #fff; border: none; border-radius: 5px; cursor: pointer; font-size: 14px; } .error-message { color: red; margin-top: 5px; } ul { margin-top: 10px; padding-left: 0; } li { list-style: none; margin-bottom: 5px; background-color: #f5f5f5; padding: 10px; border-radius: 5px; color: #333; font-size: 14px; } li:hover { background-color: #e0e0e0; } </style> </body> </html>