待办事项小程序开发

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 }); } });

相关推荐
前端 贾公子5 分钟前
第 5 章:Codex 从可运行程序到可交付工具
java·前端·数据库
用户3600555790028 分钟前
Kestrel_VLLM - 26 · 发射空档三步曲:事件计时 → nsys → 判别实验
前端
echome88832 分钟前
JavaScript async/await 错误处理:别让 Promise 静默失败
开发语言·前端·javascript·promise
PedroQue991 小时前
v0.2.0 架构升级:class + reactive 重塑状态管理
前端·uni-app
鶴哥只手遮天1 小时前
Angular 22 源码级深度解析-第 02 章 编译链路总览:从模板字符串到 `ɵɵ` 指令
前端·开源·angular.js
尘世中一位迷途小书童1 小时前
别再堆万字 Prompt:用 Agent Skills 给团队写一个「前端 Review」Skill
前端·ai编程·cursor
aixingpan1 小时前
aixingpan.cn API开发文档:api_docs_bichart_common2接口指南
前端·php
super_Omni1 小时前
text/PDF/Word → 解析成纯文本 → 分词 → 词表匹配 → 加权打分 → 低于阈值
前端·chrome
阶进遐1 小时前
浏览器工具自制指南·对话导出(3):消息池设计
前端
SameX1 小时前
HarmonyOS 用 relationalStore 做阅读统计 App —— 5 张表背后的 5 个 schema 决策
前端