screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> </head> <body> <div id="app"> <h3>Vue Add item to Object</h3> <input v-model="newItem.id" type="text" placeholder="Enter ID" /> <input v-model="newItem.name" type="text" placeholder="Enter Name" /> <button @click="addItem">Add Item</button> <ul> <li v-for="(item, index) in items" :key="index">{{ item.id }}: {{ item.name }}</li> </ul> </div> <script type="module"> const app = Vue.createApp({ data() { return { items: [], newItem: { id: "", name: "", }, }; }, methods: { addItem() { if (this.newItem.id !== "" && this.newItem.name !== "") { this.items.push({ id: this.newItem.id, name: this.newItem.name, }); this.newItem.id = ""; this.newItem.name = ""; } }, }, });app.mount("#app"); </script> <style scoped> /* Set default font family and size */ body { font-family: Arial, sans-serif; font-size: 14px; } /* Center the container */ #app { margin: 0 auto; max-width: 500px; } /* Style the input fields */ input[type="text"] { padding: 10px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 4px; width: 100%; } /* Style the button */ button { background-color: #4CAF50; border: none; color: white; padding: 10px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin-bottom: 10px; border-radius: 4px; cursor: pointer; } /* Style the list items */ li { list-style: none; padding: 10px; background-color: #f2f2f2; margin-bottom: 5px; border-radius: 4px; } /* Style the list item ID */ li span { font-weight: bold; } </style> </body> </html>