screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3.2.12/dist/vue.global.js"></script> </head> <body> <div id="app"> <div class="todo-container"> <h3>Vuejs Todo List Example</h3> <input type="text" v-model="newTodo" class="todo-input" /> <button @click="addTodo" class="todo-button"> {{ editIndex !== -1 ? 'Edit Todo' : 'Add Todo' }} </button> <ul class="todo-list"> <li v-for="(todo, index) in todos" :key="index" class="todo-item"> <input type="checkbox" @change="toggleComplete(index)" class="todo-checkbox" /> <span :style="{ textDecoration: todo.completed ? 'line-through' : 'none', color: todo.completed ? 'red' : 'black' }" class="todo-text" > {{ todo.text }} </span> <button @click="removeTodo(index)" class="todo-remove-button"> Remove </button> <button @click="editTodo(index)" class="todo-edit-button"> Edit </button> </li> </ul> </div> </div> <script type="module"> const app = Vue.createApp({ data() { return { todos: [], newTodo: "", editIndex: -1, }; }, methods: { addTodo() { if (this.newTodo.trim() !== "") { if (this.editIndex !== -1) { const updatedTodos = [...this.todos]; updatedTodos[this.editIndex] = { text: this.newTodo, completed: false, }; this.todos = updatedTodos; this.newTodo = ""; this.editIndex = -1; } else { this.todos.push({ text: this.newTodo, completed: false }); this.newTodo = ""; } } }, removeTodo(index) { this.todos = this.todos.filter((_, i) => i !== index); }, toggleComplete(index) { if (index >= 0 && index < this.todos.length) { this.todos[index].completed = !this.todos[index].completed; } }, editTodo(index) { this.newTodo = this.todos[index].text; this.editIndex = index; }, }, }); app.mount("#app"); </script> <style> #app { max-width: 400px; background-color: #ffffff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); margin: 0 auto; } .todo-container { text-align: center; } h3 { font-size: 24px; margin-bottom: 20px; } .todo-input { width: 100%; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 4px; margin-bottom: 10px; box-sizing: border-box; } .todo-button { background-color: #007bff; color: #ffffff; padding: 10px 20px; font-size: 16px; border: none; border-radius: 4px; cursor: pointer; } .todo-button:hover { background-color: #0056b3; } .todo-list { list-style: none; padding: 0; } .todo-item { display: flex; align-items: center; padding: 10px; border-bottom: 1px solid #ccc; } .todo-text { flex: 1; font-size: 16px; } .todo-remove-button, .todo-edit-button { background-color: #f44336; color: #ffffff; padding: 5px 10px; font-size: 14px; border: none; border-radius: 4px; cursor: pointer; margin-left: 10px; } .todo-remove-button:hover, .todo-edit-button:hover { background-color: #d32f2f; } .todo-remove-button { margin-right: 5px; } </style> </body> </html>