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. ...
随机推荐
- node种buffer对象数组 深拷贝浅拷贝问题
node的一个上位机和下位机通信的转发程序,用的是udp转发. 其中在发送的时候会进行一次rc4加密数据 出现问题就在这个加密数据这一块,因为这个是升级包广播发送.提前生成了升级用的广播报文,是一个b ...
- 编程中的幂等性 —— HTTP幂等性
幂等(idempotent.idempotence)是一个数学与计算机学概念,常见于抽象代数中. 在编程中.一个幂等操作的特点是其任意多次执行所产生的影响均与一次执行的影响相同.幂等函数,或幂等方法, ...
- 阻止a链接跳转的点击事件
<a href="http://www.baidu.com" id="btn">按钮</a> <script> docume ...
- sklearn.metrics中的评估方法
https://www.cnblogs.com/mindy-snail/p/12445973.html 1.confusion_matrix 利用混淆矩阵进行评估 混淆矩阵说白了就是一张表格- 所有正 ...
- LeetCode 938. 二叉搜索树的范围和
题目链接:https://leetcode-cn.com/problems/range-sum-of-bst/ 给定二叉搜索树的根结点 root,返回 L 和 R(含)之间的所有结点的值的和. 二叉搜 ...
- SpringBoot整合ActiveMQ开启持久化
1.开启队列持久化 只需要添加三行代码 jmsTemplate.setDeliveryMode(2); jmsTemplate.setExplicitQosEnabled(true); jmsTemp ...
- kanbanflow的使用
也许在工作中大家都听说过番茄工作法,就是每次在一个番茄钟25分钟内保持高度专注,并且在时间结束的时候会提醒你,然后稍作休息5分钟:此外,在产品迭代开发过程中常常会接受到不同的task:那么,我们是否可 ...
- ubuntu中的Linux安装程序的方法
Ubuntu: 1.下载.deb文件,下载后,cd到.deb文件目录,然后使用sudo dpkg -i xxx.deb dpkg=debian packager的缩写 -i=install ...
- CSS的列表样式和网页背景
CSS的列表样式 1. 设置title和列表 HTML: <!DOCTYPE html><html lang="en"><head> &l ...
- CSS的文本样式
CSS的文本样式 1.颜色 2.文本对齐方式 3.首行缩进 4.行高 5.装饰 1. 文本位置 居中: text-align: center; 靠左: text-align: left; 靠右: te ...