案例--vue_todolist

2024-03-19 16:18

本文主要是介绍案例--vue_todolist,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

封装--localStorage本地化存储[持久化]

封装--localStorage本地化存储[持久化]_tby_pr的博客-CSDN博客


js

const store = new Store;
const key = ['todolist', 'donelist']
//初始化数据
store.set(key[0], [])
store.set(key[1], [])const vm = new Vue({el: '#root',data: {//用户输入的内容cnt: '',//全选按钮all: false,//两个列表todolist: store.get(key[0]) || [],donelist: store.get(key[1]) || [],//两个列表的显示todo: true,done: false,//关键词keyword: ['admin', '小明', '小刚']},methods: {//切换显示toggle() {this.todo = true;this.done = false},toggle1() {this.todo = false;this.done = true},//批量添加按钮                add_all() {this.todolist = store.get(key[0])this.donelist = store.get(key[1])//加入之前判断一下是否有数据if (this.todolist.length) {this.todolist.forEach(item => this.donelist.push(item))store.set(key[1], this.donelist)this.todolist = []store.set(key[0], this.todolist)} else {alert('请先添加数据!')}},// 添加submit(ev) {//输入的内容不呢个超过10个,不能少于2个if (this.cnt.length < 2 || this.cnt.length >= 10) return alert('输入内容不能超过10个不能少于2个!!!')// 敏感词不可以提交!!!!!!!!!!!!!!!!!!!!!!!!const req = this.keyword.some(item => {return this.cnt.indexOf(item) !== -1})if (req) {alert('输入内容包含关键词,请重新输入!')} else {this.todolist = store.get(key[0])this.todolist.push({ id: Date.now(), name: this.cnt })store.set(key[0], this.todolist)this.cnt = ''}},// 删除按钮del(ev) {this.todolist = this.todolist.filter((item) => {return item.id !== ev.target.id - 0})store.set(key[0], this.todolist)this.donelist = this.donelist.filter((item) => {return item.id !== ev.target.id - 0})store.set(key[1], this.donelist)},//todolist 里面的已完成按钮finish(ev) {const arr = this.todolist.filter((item) => {return item.id === ev.target.id - 0})console.log(arr);this.todolist = this.todolist.filter((item) => {return item.id !== ev.target.id - 0})store.set(key[0], this.todolist)this.donelist = store.get(key[1])this.donelist.push(arr[0])store.set(key[1], this.donelist)},//donelist 里面的未完成按钮unfinish(ev) {const arr = this.donelist.filter((item) => {return item.id === ev.target.id - 0})this.donelist = this.donelist.filter((item) => {return item.id !== ev.target.id - 0})store.set(key[1], this.donelist)this.todolist = store.get(key[0])this.todolist.push(arr[0])store.set(key[0], this.todolist)}},
})

html

<div id="root"><ul><li @click="toggle()">todo</li><li @click="toggle1()">done</li></ul><ol v-show="todo"><!-- 输入框 --><input type="text" v-model.trim="cnt" @keyup.enter="submit" placeholder="请输入内容"><input type="checkbox" v-model="all" class="all">全选<button v-show='all' @click="add_all">批量添加已完成</button><li v-for="(item,key,index) in todolist"><input type="checkbox" v-model="all" :id="item.id">{{item.name}}<button :id="item.id" @click="del">删除</button><button :id="item.id" @click="finish">已完成</button></li></ol><ol v-show="done" style="margin-top: 60px;"><li v-for="(item,key,index) in donelist"><input type="checkbox">{{item.name}}<button :id="item.id" @click="del">删除</button><button :id="item.id" @click="unfinish">未完成</button></li></ol>
</div>

css

* {margin: 0;padding: 0;
}
ul,ol,li {list-style: none;
}
#root {width: 400px;min-height: 300px;border: 1px solid #333;margin: 100px auto;
}
ul>li {float: left;width: 199px;text-align: center;height: 40px;font-size: 24px;border-bottom: 1px solid #333;border-right: 1px solid #333;
}
ol {width: 100%;min-height: 258px;margin-top: 20px;
}
input[type="text"] {width: 90%;height: 30px;margin: 20px;padding-left: 14px;
}
.all {margin-left: 20px;
}
ol>li {min-width: 90%;height: 40px;padding-left: 20px;
}

这篇关于案例--vue_todolist的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/826563

相关文章

HTML5的input标签的`type`属性值详解和代码示例

《HTML5的input标签的`type`属性值详解和代码示例》HTML5的`input`标签提供了多种`type`属性值,用于创建不同类型的输入控件,满足用户输入的多样化需求,从文本输入、密码输入、... 目录一、引言二、文本类输入类型2.1 text2.2 password2.3 textarea(严格

Springboot3 ResponseEntity 完全使用案例

《Springboot3ResponseEntity完全使用案例》ResponseEntity是SpringBoot中控制HTTP响应的核心工具——它能让你精准定义响应状态码、响应头、响应体,相比... 目录Spring Boot 3 ResponseEntity 完全使用教程前置准备1. 项目基础依赖(M

SpringBoot返回文件让前端下载的几种方式

《SpringBoot返回文件让前端下载的几种方式》文章介绍了开发中文件下载的两种常见解决方案,并详细描述了通过后端进行下载的原理和步骤,包括一次性读取到内存和分块写入响应输出流两种方法,此外,还提供... 目录01 背景02 一次性读取到内存,通过响应输出流输出到前端02 将文件流通过循环写入到响应输出流

SpringBoot+Vue3整合SSE实现实时消息推送功能

《SpringBoot+Vue3整合SSE实现实时消息推送功能》在日常开发中,我们经常需要实现实时消息推送的功能,这篇文章将基于SpringBoot和Vue3来简单实现一个入门级的例子,下面小编就和大... 目录前言先大概介绍下SSE后端实现(SpringBoot)前端实现(vue3)1. 数据类型定义2.

C++11中的包装器实战案例

《C++11中的包装器实战案例》本文给大家介绍C++11中的包装器实战案例,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录引言1.std::function1.1.什么是std::function1.2.核心用法1.2.1.包装普通函数1.2.

Redis 命令详解与实战案例

《Redis命令详解与实战案例》本文详细介绍了Redis的基础知识、核心数据结构与命令、高级功能与命令、最佳实践与性能优化,以及实战应用场景,通过实战案例,展示了如何使用Redis构建高性能应用系统... 目录Redis 命令详解与实战案例一、Redis 基础介绍二、Redis 核心数据结构与命令1. 字符

前端Visual Studio Code安装配置教程之下载、汉化、常用组件及基本操作

《前端VisualStudioCode安装配置教程之下载、汉化、常用组件及基本操作》VisualStudioCode是微软推出的一个强大的代码编辑器,功能强大,操作简单便捷,还有着良好的用户界面,... 目录一、Visual Studio Code下载二、汉化三、常用组件1、Auto Rename Tag2

通过DBeaver连接GaussDB数据库的实战案例

《通过DBeaver连接GaussDB数据库的实战案例》DBeaver是一个通用的数据库客户端,可以通过配置不同驱动连接各种不同的数据库,:本文主要介绍通过DBeaver连接GaussDB数据库的... 目录​一、前置条件​二、连接步骤​三、常见问题与解决方案​1. 驱动未找到​2. 连接超时​3. 权限不

Java中的随机数生成案例从范围字符串到动态区间应用

《Java中的随机数生成案例从范围字符串到动态区间应用》本文介绍了在Java中生成随机数的多种方法,并通过两个案例解析如何根据业务需求生成特定范围的随机数,本文通过两个实际案例详细介绍如何在java中... 目录Java中的随机数生成:从范围字符串到动态区间应用引言目录1. Java中的随机数生成基础基本随

SpringMVC配置、映射与参数处理​入门案例详解

《SpringMVC配置、映射与参数处理​入门案例详解》文章介绍了SpringMVC框架的基本概念和使用方法,包括如何配置和编写Controller、设置请求映射规则、使用RestFul风格、获取请求... 目录1.SpringMVC概述2.入门案例①导入相关依赖②配置web.XML③配置SpringMVC