当前位置: 首页 > 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.xdnf.cn/news/1300267.html

相关文章:

  • 【C#】PNG 和 JPG、JPEG的应用以及三种格式的区别?
  • 2025天府杯数学建模C题
  • RxJava Android 创建操作符实战:从数据源到Observable
  • Java应用架构实战指南:主流模式解析与Spring落地实践
  • Java面试宝典:JVM性能优化
  • 多任务并发:进程管理的核心奥秘
  • Java中Record的应用
  • Java使用Apache POI读取Excel文件
  • Swift 实战:用链表和哈希表写出高性能的贪吃蛇引擎(LeetCode 353)
  • C#WPF实战出真汁01--项目介绍
  • SpringBoot+Vue线上部署MySQL问题解决
  • 代码随想录Day50:图论(图论理论、深度搜索理论、所有可达路径、广度搜索理论)
  • Linux软件下载菜单脚本
  • 【数据分享】2014-2023年长江流域 (0.05度)5.5km分辨率的每小时日光诱导叶绿素荧光SIF数据
  • 【记录】Apache SeaTunnel 系统监控信息
  • 深度学习-卷积神经网络CNN-批量归一化 BatchNorm
  • PostgreSQL——触发器
  • 零基础-动手学深度学习-10.3. 注意力评分函数
  • 最新去水印小程序系统 前端+后端全套源码 多套模版 免授权(源码下载)
  • vue3,使用v-draggable拖动时卡顿的问题
  • 减重小知识
  • Linux 文件系统简介
  • OpenCV 形态学操作
  • GitHub 仓库代码上传指南
  • 开发避坑指南(26):Vue3 input输入框前置后 置元素解决方案
  • Mybatis学习笔记(三)
  • diffusers库学习--pipeline,模型,调度器的基础使用
  • springboot博客实战笔记02
  • C#WPF实战出真汁04--登录功能实现
  • C#WPF实战出真汁03--登录界面设计