4. 代码示例: ```html <template> <div> <h1>this is a todolist</h1> <input type="text" v-model="newItem" @keyup.enter="addItem"> <ul> <li v-for="(item, index) in items" :key="index" @click="toggleItem(index)" :class="{ completed: item.completed }">{{ item.text }}</li> </ul> </div> </template> <script> export default { data() { return { newItem: '', items: [] }; }, methods: { addItem() { if (this.newItem.trim() !== '') { this.items.push({ text: this.newItem, completed: false }); this.newItem = ''; } }, toggleItem(index) { this.items[index].completed = !this.items[index].completed; } } }; </script> <style> .completed { text-decoration: line-through; } </style> ``` 5. 运行项目: - 使用vue cli初始化项目:`vue create todolist-app` - 将以上代码分别添加到`App.vue`、`App.js`、`App.css`中 - 在终端中进入项目目录并运行:`npm run serve` - 打开浏览器并访问`http://localhost:8080/`即可看到待办事项列表应用 通过以上步骤,您就可以创建一个简单的待办事项列表应用,实现添加和编辑功能。希望对您有帮助! [2024-11-21 17:51:53 | AI写代码神器 | 766点数解答]