当前位置: 首页 > news >正文

待办事项小程序开发

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"
}

<view class="container"><view class="header"><inputplaceholder="添加待办事项"value="{{inputValue}}"bindinput="inputChange"bindconfirm="addTodo"/><button bindtap="addTodo">添加</button></view><view class="todo-list"><viewwx:for="{{todos}}"wx:key="id"class="todo-item {{item.done ? 'done' : ''}}"bindtap="toggleTodo"data-id="{{item.id}}"><text>{{item.text}}</text><button bindtap="deleteTodo" data-id="{{item.id}}">删除</button></view></view>
</view>

.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 });}
});
http://www.lryc.cn/news/621419.html

相关文章:

  • Multimodal RAG Enhanced Visual Description
  • 容器运行时支持GPU,并使用1panel安装ollama
  • 【嵌入式C语言】四
  • 20道前端性能优化面试题精华
  • python学习DAY41打卡
  • 低配硬件运行智谱GLM-4.5V视觉语言模型推理服务的方法
  • 《WebGL中FBO的底层运行逻辑》
  • 基于ECharts和EdgeOne打造云上智能图表
  • 编排之神-Kubernetes中的微服务介绍及演练
  • (2-10-1)MyBatis的基础与基本使用
  • 大数据项目_基于Python+hadopp的城市空气污染数据关联性可视化分析系统源码_基于机器学习的城市空气污染预测与分析系统的设计与实现
  • C/C++ 进阶:深入解析 GCC:从源码到可执行程序的魔法四步曲
  • 卫星通信链路预算之七:上行载噪比计算
  • 【C#】PNG 和 JPG、JPEG的应用以及三种格式的区别?
  • [系统架构设计师]软件工程基础知识(五)
  • 《量子雷达》第5章 量子雷达发射机 预习2025.8.14
  • “Zen 5”: The AMD High-Performance 4nm x86-64 Microprocessor Core
  • 接口测试用例的编写
  • Avalonia_SukiUI明暗主题切换时部分元素颜色不变
  • vue内置组件
  • 基于wireshark的USB 全速硬件抓包工具USB Sniffer Lite的使用
  • 打靶日常-CSRF
  • pytorch学习笔记-加载现有的网络模型(VGG16)、增加/修改其中的网络层(修改为10分类)
  • 分布式锁—Redisson的公平锁
  • 如何更好地使用AI编程?
  • MySQL窗口函数与PyMySQL以及SQL注入
  • C#笔记啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
  • JavaScript 解构赋值语法详解
  • 开源卫星软件平台LibreCube技术深度解析
  • DAY 42 Grad-CAM与Hook函数