待办事项小程序开发

1. 项目规划

  • 功能需求

  • 添加待办事项

  • 标记完成/未完成

  • 删除待办事项

  • 分类或标签管理(可选)

  • 数据持久化(本地存储)

2. 实现功能

  • 添加待办事项

  • 监听输入框和按钮事件,将输入内容添加到列表。

  • 标记完成/未完成

  • 使用复选框或滑动操作,更新事项状态。

  • 删除待办事项

  • 支持左滑删除或长按删除。

  • 数据持久化

  • 使用本地存储待办事项数据。

3. 代码实现

基于微信小程序开发一个待办事项应用,主要包括以下功能:

  1. 创建待办事项
  2. 标记完成状态
  3. 删除待办事项
  4. 本地存储待办事项数据

首先,我会创建以下文件:

  1. app.json - 小程序全局配置

  2. pages/index/index.js - 页面逻辑

  3. pages/index/index.wxml - 页面结构

  4. pages/index/index.wxss - 页面样式

  5. pages/index/index.json - 页面配置

    { "pages": "pages/index/index", "window": { "navigationBarTitleText": "待办事项", "navigationBarBackgroundColor": "#ffffff", "navigationBarTextStyle": "black" }, "style": "v2", "sitemapLocation": "sitemap.json" }
    添加 {{item.text}} 删除

    .container { padding: 20px; } .header { display: flex; margin-bottom: 20px; } .header input { flex: 1; margin-right: 10px; padding: 10px; border: 1px solid #ccc; border-radius: 4px; } .todo-list { margin-top: 20px; } .todo-item { display: flex; justify-content: space-between; align-items: center; padding: 10px; margin-bottom: 10px; border: 1px solid #eee; border-radius: 4px; } .todo-item.done { text-decoration: line-through; color: #999; }

    Page({ data: { todos: \[\], inputValue: '' }, onLoad() { this.loadTodos(); }, loadTodos() { const todos = wx.getStorageSync('todos') || \[\]; this.setData({ todos }); }, saveTodos() { wx.setStorageSync('todos', this.data.todos); }, addTodo() { if (!this.data.inputValue.trim()) return; const newTodo = { id: Date.now(), text: this.data.inputValue, done: false }; this.setData({ todos: ...this.data.todos, newTodo, inputValue: '' }, this.saveTodos); }, toggleTodo(e) { const { id } = e.currentTarget.dataset; const todos = this.data.todos.map(todo => todo.id === id ? { ...todo, done: !todo.done } : todo ); this.setData({ todos }, this.saveTodos); }, deleteTodo(e) { const { id } = e.currentTarget.dataset; const todos = this.data.todos.filter(todo => todo.id !== id); this.setData({ todos }, this.saveTodos); }, inputChange(e) { this.setData({ inputValue: e.detail.value }); } });

相关推荐
亿元程序员2 分钟前
还有高手?用Shader让图片中的3D圆环转起来!
前端
灯澜忆梦4 分钟前
【基于GO的Web开发14】gin请求重定向
前端·后端·golang·gin
qq_452396235 分钟前
第十一篇:《前端性能优化体系:从加载到交互的全链路》
前端·性能优化·交互
Mh8 分钟前
听说我兄弟喜欢跑车,所以必须安排上
前端·javascript·vue.js
zttbee9 分钟前
vue学习(白话功能版)
前端·vue.js·学习·前端框架
qq_4260039610 分钟前
多语言新增语种全量测试策略
前端·javascript·python·pycharm·自动化
黄敬峰16 分钟前
从零搭建 Next.js 单词管理系统:Supabase + Drizzle ORM + shadcn/ui 全栈实战
javascript·面试
nicole bai18 分钟前
前端封装el-table及注意点
前端·javascript·vue.js
晨枫阳28 分钟前
Vue 前端构建工具链完全理解指南
前端·javascript·vue.js
言乐628 分钟前
Python关于老游复刻与创新2
前端·javascript·css·python·css3