首页 > 其他分享 >假期vue学习笔记07 todo事件的本地存储

假期vue学习笔记07 todo事件的本地存储

时间:2024-02-28 17:49:02浏览次数:18  
标签:vue 07 todo li 1px margin height border

 用本地存储改写前面的todo案例

 

<template>         <li>             <label >                 <input type="checkbox" :checked="todo.done" @change="handleCheck(todo.id)"/>                 <span v-show="!todo.isEdit">{{todo.title}}</span>                 <input                 type="text"                 :value="todo.title"                 v-show="todo.isEdit"                 @blur="handleBlur(todo,$event)"                 ref="inputTitle"                 >             </label>             <button class="btn btn-danger" @click="deleteID(todo.id)">删除</button>             <button v-show="!todo.isEdit" class="btn btn-edit" @click="handleEdit(todo)" >编辑</button>         </li> </template>
<script>     export default {         nmae:'Item',         //接受对象         props:['todo'],         methods: {             handleCheck(id){                 //通知APP取反                 this.$bus.$emit('checkTodo',id)             },             deleteID(id){                 if(confirm('确认删除么?')){                     this.$bus.$emit('deleteTodo',id)                 }             },             //编辑             handleEdit(todo){                 if(Object.hasOwnProperty.call(todo, 'isEdit')){                     todo.isEdit = true                 }else{                     this.$set(todo,'isEdit',true) //响应式的                 }                 this.$nextTick(function(){                     this.$refs.inputTitle.focus()                 })             },             handleBlur(todo,e){                 todo.isEdit = false                 if(!e.target.value.trim()) return alert('输入不能为空')                 this.$bus.$emit('updateTodo',todo.id,e.target.value)             }         },     } </script>
<style scoped>     li{         list-style: none;         height: 36px;         line-height: 36px;         padding:0 5px;         border-bottom: 1px solid #ddd;     }     li label{         float: left;         cursor:pointer;     }
    li label li input{         vertical-align: middle;         margin-right: 6px;         position: relative;         top: -1px;     }
    li button{         float: right;         margin-top: 3px;     }
    li::before{         content: initial;     }
    li:last-child{         border-bottom: none;     } </style>   <template>     <ul class="todo-main">        <Item v-for="(todoObj) in todos"        :key="todoObj.id"        :todo="todoObj"        />     </ul> </template>
<script>     import Item from './Item.vue'     export default {         nmae:'List',         components:{              Item          },          props:['todos']     } </script>
<style scoped>     .todo-main{         margin-left: 0px;         border:1px solid #ddd;         border-radius: 2px;         padding: 0px;     }     .todo-empty{         height: 40px;         line-height: 40px;         border: 1px solid #ddd;         border-radius: 2px;         padding-left: 5px;         margin-top: 10px;     } </style>   <template>     <div class="todo-footer" v-show="todos.length">         <label>             <input type="checkbox" :checked="isAll" @change="checkAll">         </label>         <span>             <span>已完成{{doneTotal}}/全部{{ todos.length }}</span>         </span>         <button class="btn btn-danger"  @click="clearAll">清除已完成任务</button>     </div> </template>
<script>     export default {         nmae:'MyFooter',         props:['todos','checkAllTodo','clearTotal'],         computed:{             doneTotal(){                return  this.todos.reduce((pre,current)=>pre + (current.done ? 1 : 0),0)             },             isAll(){                 return this.doneTotal === this.todos.length && this.todos.length > 0             }         },         methods:{             checkAll(e){                 this.checkAllTodo(e.target.checked)             },             clearAll(){                 this.clearTotal()             }         }     } </script>
<style scoped>     .todo-footer{         height: 40px;         line-height: 40px;         padding-left: 6px;         margin-top: 5px;     }
    .todo-footer label{         display: inline-block;         margin-right: 20px;         cursor: pointer;     }
    .todo-footer label input{         position: relative;         top: -1px;         vertical-align: middle;         margin-right: 5px;     }      .todo-footer button{             float:right;             margin-top: 5px;         } </style>     <template>     <div class="todo-header">         <input type="text" placeholder="请输入你的任务名称按回车确认" @keyup.enter="add" />     </div> </template>
<script>     import {nanoid} from 'nanoid'     export default {         nmae:'Top',         methods: {             add(element){                 //校验数据                 if(!element.target.value) return                 //将用户输入包装成一个todo对象                 const todoObj = {id:nanoid(),title:element.target.value,done:false}                 this.$emit('addTodo',todoObj)                 element.target.value=''             }         },     } </script>
<style scoped>     .to-header input{         width: 700px;         height: 28px;         font-size: 14px;         border: 1px solid #ccc;         border-radius: 4px;         padding: 4px 7px;     }     .todo-header input:focus{         outline: none;         border-color: rgba(82,168,236,0.8);         box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075),0 0 8px rgba(82,168,236,0.8);     } </style>    

标签:vue,07,todo,li,1px,margin,height,border
From: https://www.cnblogs.com/hbro/p/18041218

相关文章

  • 假期vue学习笔记08 绑定和解绑
     <template>  <divclass="app">    <h1>{{msg}}</h1>    <!--props子给父传递事件-->    <School:getSchoolName="getSchoolName"/>    <!--通过父组件给子组件绑定一个自定义事件实现:子给父传递数据(第一种写法,使用@过v-......
  • 假期vue学习笔记09 全局事件总栈
     <template>  <div class="school">    <h2>学校名称:{{name}}</h2>     <h2>学校地址:{{address}}</h2>  </div></template><script>  exportdefault{    name:'School'......
  • 假期vue学习笔记10 pubsub
     <template>  <divclass="app">    <h1>{{msg}}</h1>    <School/>    <Student/>  </div></template><script>importStudentfrom'./components/Student.vue'imp......
  • 假期vue学习笔记11 动画
    <template>  <divid="root">    <Test/>    <Test2/>    <Test3/>  </div></template><script>importTestfrom'./components/Test.vue'importTest2from'./comp......
  • 假期vue学习笔记01 ref
    <template>  <div>    <h1v-text="msg"ref="title"></h1>    <button@click="showDOM">点我输出上方的DOM元素</button>    <School/>  </div></template><script......
  • 假期vue学习笔记02 mixin
    <template>  <div >    <h2@click="showName">学校名称:{{name}}</h2>     <h2>学校地址:{{address}}</h2>  </div></template><script>  exportdefault{    name:'School'......
  • javaweb02-JavaScript&vue
    JavaScript控制网页行为js引入方式内部脚本:script标签外部脚本:js文件js基础语法书写语法区分大小写每行结尾分号可有可无,建议写上输出语句警告框window.alerthtml输出document.write浏览器控制台console.log变量用var关键字声明变量JavaScript是一......
  • 假期vue学习笔记04 插件
    exportdefault{  install(Vue){    //全局过滤器    Vue.filter('mySclice',function(value){      returnvalue.slice(0,4)    }),    //定义全局指令    Vue.directive('fbind',{      bind(......
  • 【vue】做一个从右边出来又回去的一个抽屉div
    前言:工作需要做一个从右往左出现的一个弹窗,要有抽屉效果,看了网上各种方法好多都不能用,最后试了一种可以用,但是忘记是哪个网址了,现在就是自己写一下这个随便以后用到方便找。做一个从右边出来又回去的一个抽屉divhtml代码<divclass="addBtn"@click="show">点击按钮出......
  • 面试题 02.07. 链表相交C
    利用链表的特性,如果相交的话,后面就不可能岔开!你可以想象把他们有同一个尾巴,然后从尾巴往前看。所以只要知道两个链表的长度,就可以在同一起跑线上一起比较了。/***Definitionforsingly-linkedlist.*structListNode{*intval;*structListNode*next;......