分享一个vue实现的记事本功能案例


Posted in Vue.js onApril 11, 2022

直接上代码:

<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="./css/index.css">
</head>
 
<body>
    <!-- 
    1.用户输入待办事项,回车后添加到“正在进行”,并清空文本框  
    2.在“正在进行”列表中单击列表项,添加到 已完成 列表  
    3.在“已经完成”列表中单击列表项,添加到 正在进行 列表 
    4.在响应列表项中点击 删除  删除 该项目。
   -->
    <div id="app">
        <header>
            <section>
                <label for="title"></label>
                <input type="text" v-model="thing" placeholder="添加ToDo" required="required" autocomplete="off" @keydown.13="add">
            </section>
        </header>
        <section>
            <h2>正在进行<span>{{ongoing.length}}</span></h2>
            <ol id="todolist" class="demo-box">
                <li v-for="(item,index) in ongoing" :key="item.id">
                    <input type="checkbox" @click="addToDone(index)"> {{item.title}}
                    <button @click="delGoing(index)">删除</button>
                </li>
            </ol>
            <h2>已完成<span>{{done.length}}</span></h2>
            <ul id="donelist">
                <li v-for="(item,index) in done" :key="item.id">
                    <input type="checkbox" checked @click="addToGoing(index)"> {{item.title}}
                    <button @click="delDone(index)">删除</button>
                </li>
            </ul>
        </section>
    </div>
    <footer>
        Copyright &copy; 2021 todolist.cn
    </footer>
    <script src="../vue.js"></script>
    <script>
        new Vue({
            el: "#app",
            data: {
                id: 4,
                //存储用户输入的信息
                thing: "",
                /* 正在进行 列表 */
                ongoing: [{
                    id: 1,
                    title: "吃饭"
                }, {
                    id: 2,
                    title: "睡觉"
                }],
                //已经完成 列表
                done: [{
                    id: 3,
                    title: "打豆豆"
                }]
            },
            methods: {
                //添加到待办事项
                add() {
                    //组装一个对象,将对象添加到ongoing数组中。
                    let obj = {
                        id: this.id,
                        title: this.thing
                    };
                    //新的对象产生,id自增,防止id重复。
                    this.id++;
                    /* 把获取到的值添加到待办事项 */
                    this.ongoing.push(obj);
                    //将thing的值设置为空,则输入框自动清空
                    this.thing = "";
                },
                //添加到已经完成
                addToDone(index) {
                    //将点击的数据 从ongoing 删除,添加到 Done中
                    //splice(index,1)从index开始,删除一个元素。 splice会返回被删除的元素组成的数组。
                    this.done.push(this.ongoing.splice(index, 1)[0])
                },
                /* 添加到正在进行 */
                addToGoing(index) {
                    this.ongoing.push(this.done.splice(index, 1)[0])
                },
                /* 从正在进行中删除 */
                delGoing(index) {
                    this.ongoing.splice(index, 1)
                },
                /* 从已经完成中删除 */
                delDone(index) {
                    this.done.splice(index, 1)
                }
            }
        })
    </script>
</body>
 
</html>

样式部分

body {
  margin: 0;
  padding: 0;
  font-size: 16px;
  background: #CDCDCD;
}
 
header {
  height: 50px;
  background: #333;
  background: rgba(47, 47, 47, 0.98);
}
 
section {
  margin: 0 auto;
}
 
label {
  float: left;
  width: 100px;
  line-height: 50px;
  color: #DDD;
  font-size: 24px;
  cursor: pointer;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
 
header input {
  float: right;
  width: 60%;
  height: 24px;
  margin-top: 12px;
  text-indent: 10px;
  border-radius: 5px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.24), 0 1px 6px rgba(0, 0, 0, 0.45) inset;
  border: none
}
 
input:focus {
  outline-width: 0
}
 
h2 {
  position: relative;
}
 
span {
  position: absolute;
  top: 2px;
  right: 5px;
  display: inline-block;
  padding: 0 5px;
  height: 20px;
  border-radius: 20px;
  background: #E6E6FA;
  line-height: 22px;
  text-align: center;
  color: #666;
  font-size: 14px;
}
 
ol,
ul {
  padding: 0;
  list-style: none;
}
 
li input {
  position: absolute;
  top: 2px;
  left: 10px;
  width: 22px;
  height: 22px;
  cursor: pointer;
}
 
p {
  margin: 0;
}
 
li p input {
  top: 3px;
  left: 40px;
  width: 70%;
  height: 20px;
  line-height: 14px;
  text-indent: 5px;
  font-size: 14px;
}
 
li {
  height: 32px;
  line-height: 32px;
  background: #fff;
  position: relative;
  margin-bottom: 10px;
  padding: 0 45px;
  border-radius: 3px;
  border-left: 5px solid #629A9C;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07);
}
 
ol li {
  cursor: move;
}
 
ul li {
  border-left: 5px solid #999;
  opacity: 0.5;
}
 
li a {
  position: absolute;
  top: 2px;
  right: 5px;
  display: inline-block;
  width: 14px;
  height: 12px;
  border-radius: 14px;
  border: 6px double #FFF;
  background: #CCC;
  line-height: 14px;
  text-align: center;
  color: #FFF;
  font-weight: bold;
  font-size: 14px;
  cursor: pointer;
}
 
li button{
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
}
 
footer {
  color: #666;
  font-size: 14px;
  text-align: center;
}
 
@media screen and (max-device-width: 620px) {
  section {
     width: 96%;
     padding: 0 2%;
  }
}
 
@media screen and (min-width: 620px) {
  section {
     width: 600px;
     padding: 0 10px;
  }
}

分享一个vue实现的记事本功能案例

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Vue.js 相关文章推荐
Vue Elenent实现表格相同数据列合并
Nov 30 Vue.js
用vue设计一个日历表
Dec 03 Vue.js
vue图片裁剪插件vue-cropper使用方法详解
Dec 16 Vue.js
手写Vue源码之数据劫持示例详解
Jan 04 Vue.js
解决vue使用vant轮播组件swipe + flex时文字抖动问题
Jan 07 Vue.js
手写Vue2.0 数据劫持的示例
Mar 04 Vue.js
vue3如何优雅的实现移动端登录注册模块
Mar 29 Vue.js
vue实现水波涟漪效果的点击反馈指令
May 31 Vue.js
详解Vue项目的打包方式(生成dist文件)
Jan 18 Vue.js
Vue3如何理解ref toRef和toRefs的区别
Feb 18 Vue.js
Vue中Object.assign清空数据报错的解决方案
Mar 03 Vue.js
vue实现简易音乐播放器
Aug 14 Vue.js
vue代码分块和懒加载非必要资源文件
Apr 11 #Vue.js
vue打包时去掉所有的console.log
三种方式清除vue路由跳转router-link的历史记录
Apr 10 #Vue.js
vue route新窗口跳转页面并且携带与接收参数
Apr 10 #Vue.js
vue实力踩坑之push当前页无效
Apr 10 #Vue.js
vue实现Toast组件轻提示
Apr 10 #Vue.js
vue自定义右键菜单之全局实现
Apr 09 #Vue.js
You might like
乱谈我对耳机、音箱的感受
2021/03/02 无线电
PHP CURL CURLOPT参数说明(curl_setopt)
2013/09/30 PHP
PHP中nowdoc和heredoc使用需要注意的一点
2014/03/21 PHP
php使用curl出现Expect:100-continue解决方法
2015/03/03 PHP
PHP+jQuery+Ajax实现用户登录与退出
2015/04/27 PHP
分享PHP守护进程类
2015/12/30 PHP
Symfony2框架学习笔记之HTTP Cache用法详解
2016/03/18 PHP
django中的ajax组件教程详解
2018/10/18 PHP
用jQuery实现检测浏览器及版本的脚本代码
2008/01/22 Javascript
JS获得URL超链接的参数值实例代码
2013/06/21 Javascript
js简单的表格添加行和删除行操作示例
2014/03/31 Javascript
Javascript与jQuery方法的隐藏与显示
2015/01/19 Javascript
js实现按钮控制带有停顿效果的图片滚动
2016/08/30 Javascript
使用vue和datatables进行表格的服务器端分页实例代码
2017/06/07 Javascript
js实现前端图片上传即时预览功能
2017/08/02 Javascript
windows系统下更新nodejs版本的方案
2017/11/24 NodeJs
Intellij IDEA搭建vue-cli项目的方法步骤
2018/10/20 Javascript
9个JavaScript日常开发小技巧
2020/10/06 Javascript
简单的Python抓taobao图片爬虫
2014/10/26 Python
网红编程语言Python将纳入高考你怎么看?
2018/06/07 Python
Python将8位的图片转为24位的图片实现方法
2018/10/24 Python
使用Python Pandas处理亿级数据的方法
2019/06/24 Python
python与mysql数据库交互的实现
2020/01/06 Python
python GUI库图形界面开发之PyQt5不规则窗口实现与显示GIF动画的详细方法与实例
2020/03/09 Python
Python Selenium破解滑块验证码最新版(GEETEST95%以上通过率)
2021/01/29 Python
完美解决torch.cuda.is_available()一直返回False的玄学方法
2021/02/06 Python
来自圣地亚哥的实惠太阳镜:Knockaround
2018/08/27 全球购物
求职简历中自我评价
2014/01/28 职场文书
买房协议书
2014/04/11 职场文书
小学生感恩演讲稿
2014/04/25 职场文书
死者家属慰问信
2015/03/24 职场文书
考勤制度通知
2015/04/25 职场文书
远程教育学习心得体会
2016/01/23 职场文书
如何写好活动总结
2019/06/21 职场文书
浅析Python实现DFA算法
2021/06/26 Python
DIV CSS实现网页背景半透明效果
2021/12/06 HTML / CSS