Vue 任务清单
<style>
li{ list-style: none; }
#root{
width: 400px;
min-height: 400px;
box-shadow: 0 0 10px #666;
margin: 20px auto;
padding: 20px;
}
.task-input{
width: 100%;
height: 30px;
padding-left: 10px;
font-size: 13px;
border: 1px solid #ccc;
}
.task-count{
padding: 0;
height: 30px;
clear: both;
}
.task-count li:first-of-type{
float: left;
font-size: 14px;
color: red;
}
.task-count .action{
float: right;
padding: 0;
}
.task-count .action a{
font-size: 14px;
text-decoration: none;
color: #888;
display: inline-block;
padding: 2px 8px;
border: 1px solid #fff;
}
.task-count .action .active{
border-color: #888;
}
.tasks{
box-shadow: 0 0 2px #ccc;
padding: 10px;
}
.tasks .todo-list{
padding: 0;
margin: 0;
}
.tasks .todo-list .todo{
height: 40px;
line-height: 40px;
}
.tasks .todo-list .active{
color: #999;
text-decoration: line-through;
}
.tasks .todo-list .destroy{
color: red;
background: #fff;
border: none;
float: right;
margin-top: 12px;
cursor: pointer;
}
.tasks .todo-list .editing .view{
display: none;
}
.tasks .todo-list .editing .edit{
display: block;
}
.tasks .todo-list .edit{
display: none;
width: 80%;
padding: 4px 10px;
}
</style>
<div id="root">
<p>添加任务:</p>
<input
class="task-input"
placeholder="输入任务 回车即可添加任务"
type="text"
v-on:keyup.enter="addTodo"
v-model="todo"
>
<ul class="task-count" v-show="list.length">
<li>{{noCheckedLength}} 个任务未完成 </li>
<li class="action">
<a class="active" href="javascript:;">所有任务</a>
<a href="javascript:;">未完成的任务</a>
<a href="javascript:;">完成的任务</a>
</li>
</ul>
<p>任务列表:</p>
<div class="tasks">
<span v-show="!list.length">还没有添加任何任务</span>
<ul class="todo-list">
<todo-item
class="todo"
:class="{active: item.isChecked, editing: item === edtorTodos}"
v-for="(item, index) in list"
:content="item"
:index="index"
></todo-item>
</ul>
</div>
</div>
<script>
Vue.component('todo-item', {
props: ['content', 'index'],
template: `
<li>
<div class="view">
<input class="toggle" type="checkbox" v-model="content.isChecked">
<label @dblclick="edtorTodo(content)">{{content.title}}</label>
<button class="destroy" @click="deleteTodo(index)">x</button>
</div>
<input
type="text"
class="edit"
v-model="content.title"
@blur="edtorTodoed(content, index)"
@keyup.13="edtorTodoed(content, index)"
@keyup.esc="cancelTodo(content)"
/>
</li>
`,
data () {
return {
}
}
})
new Vue({
el: '#root',
data: {
list: [
{
title: 'xiaobai'
}
],
todo: '',
edtorTodos: '', // 记录编辑的数据
beforeTitle: ''
},
methods: {
// addTodo () {
// if(!this.todo) return;
// this.list.push({
// title: this.todo,
// isChecked: false
// })
// this.todo = '';
// },
// watch: {
// list: {
// }
// },
// deleteTodo (index) { // 删除
// this.list.splice(index, 1)
// },
// edtorTodo (todo) { // 编辑
// this.beforeTitle = todo.title;
// this.edtorTodos = todo;
// },
// edtorTodoed (todo, index) { // 编辑成功
// // 如果输入框为空 则删除列表
// if(!todo.title) this.list.splice(index, 1);
// this.edtorTodos = ''
// },
// cancelTodo (todo) { // 取消编辑
// todo.title = this.beforeTitle;
// this.edtorTodos = ''
// }
},
// directives: { // 自定义组件
// 'focus': {
// update (el, binding){
// if(binding.value){
// el.focus();
// }
// }
// }
// },
computed: {
noCheckedLength () { // 计算未完成任务的数量
return this.list.filter(function(item){
return !item.isChecked
}).length
}
}
})
</script>
Vue 任务清单的更多相关文章
- 5. Vue - 小清单实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python 全栈开发,Day89(sorted面试题,Pycharm配置支持vue语法,Vue基础语法,小清单练习)
一.sorted面试题 面试题: [11, 33, 4, 2, 11, 4, 9, 2] 去重并保持原来的顺序 答案1: list1 = [11, 33, 4, 2, 11, 4, 9, 2] ret ...
- vue实现购物清单列表添加删除
vue实现购物清单列表添加删除 一.总结 一句话总结: 基础的v-model操作,以及数组的添加(push)删除(splice)操作 1.checkbox可以绑定数组,也可以直接绑定值? 绑定数组就是 ...
- 任务清单小功能的实现(任务的增、删、改、查、存储)使用Vue实现
文章目录 1.实现的效果(视频演示) 2.重点讲解(编辑的实现) 2.1 提示(官网介绍nextTick的用法) 3.编辑功能的核心代码 4.完整的代码 5.以往练习 任务清单案例(纯Vue) 实现的 ...
- 纯Vue实现网页日常任务清单小功能(数据存储在浏览器)
任务清单可以极大提高我们的工作效率.哪些事情办了.哪些事情代办.哪些是紧急需要办的事情等等. 在组件化编码实战3的基础上进一步改进.将原先的数据保存的浏览器中.就可以做到关闭网页也不会丢失数据的情况 ...
- Vue.js优雅的实现列表清单的操作
一.Vue.js简要说明 Vue.js (读音 /vjuː/,类似于 view) 是一套构建用户界面的渐进式框架.与前端框架Angular一样, Vue.js在设计上采用MVVM模式,当Vie ...
- Vue.js优雅的实现列表清单
一.Vue.js简要说明 Vue.js (读音 /vjuː/) 是一套构建用户界面的渐进式框架.与前端框架Angular一样, Vue.js在设计上采用MVVM模式,当View视图层发生变化时 ...
- 基于vue的购物车清单
<!doctype html> <html> <head> <meta charset="utf-8"> <link rel= ...
- 窥探Vue.js 2.0
title: 窥探Vue.js2.0 date: 2016-09-27 10:22:34 tags: vue category: 技术总结 --- 窥探Vue.js2.0 令人兴奋的Vue.js 2. ...
随机推荐
- 【MySql】数据库连接异常:Thelastpacketsentsuccessfullytotheserverwas0millisecondsago
参考链接:http://blog.sina.com.cn/s/blog_7540bf5f0102xjpk.html 最近新入职,用了新版的mysql8数据库,结果连接数据库时出现了问题,报了几个异常, ...
- 使用IDA pro逆向ARM M系核心的Bin固件
使用IDA pro逆向ARM M系核心的Bin固件 物联网和智能设备这两年还是比较火的,我们的手中或多或少都有了几个智能设备,比如手环,智能手表,或者门锁什么之类的东西,但是同学们在做逆向的时候, ...
- 本地连接mysql的url写法
一.jdbc:mysql:///中三条斜杠(///) 第三个/代表什么? jdbc:mysql:///testdatabase等同于 jdbc:mysql://localhost:3306/testd ...
- Easyui-Tree和Combotree使用注意事项-sunziren
版权声明:本文为sunziren原创文章,博客园首发,转载务必注明出处以及作者名称. Easyui-Tree和Combotree所使用的数据结构是类似的,在我的上一篇文章<Easyui-Tree ...
- Java第四节课总结
动手动脑1:如果类提供了一个自定义的构造方法,将导致系统不再提供默认构造方法.Foo obj1=new Foo()在此处调用应增加参数. 动手动脑2:静态初始化块只执行一次.创建子类型的对象时,也会导 ...
- .net mvc 使用 aspose.cells导出数据
public class AsposeCellsHelper { public Workbook workBook; public Worksheet worksheet; Style style; ...
- JavaDay7(下)
问题1描述 编写一个方法,返回一个double类型二维数组,数组中的元素通过解析字符串参数获得. 代码实现: public class ArrayParser { public static void ...
- 2020牛客寒假算法基础集训营4-F树上博弈
链接:https://ac.nowcoder.com/acm/contest/3005/F来源:牛客网 题目描述 现有一个 n 个点,n-1条边组成的树,其中 1 号点为根节点. 牛牛和牛妹在树上玩游 ...
- 论文阅读笔记(九)【TIFS2020】:True-Color and Grayscale Video Person Re-Identification
Introduction (1)Motivation:在现实场景中,摄像头会因为故障呈现灰白色,或者为了节省视频的存储空间而人工设置为灰白色.灰度图像(grayscale images)由8位存储,而 ...
- Ubuntu WiFi连接问题
1,先说明下, 这种方式仅针对 RTL8723BE这款无限网卡. 先用 lspci|grep -i net 先用这个命令查询网卡型号, 我的电脑查询结果: 00:19.0 Ethernet contr ...