当前位置:   article > 正文

ToDolist_todolist官网

todolist官网

官方网址http://www.todolist.cn/

具体功能

1.添加内容 删除内容

2.本地存储

3.点击更改

css部分

  1. *{
  2. margin: 0;
  3. padding: 0;
  4. }
  5. .list {
  6. position: relative;
  7. }
  8. #app{
  9. width: 100%;
  10. height: 900px;
  11. background-color: #cdcdcd;
  12. }
  13. .h1 {
  14. width: 100%;
  15. height: 100px;
  16. line-height: 100px;
  17. background: #323232;
  18. margin: 0 auto;
  19. }
  20. .h1 span{
  21. color: #fff;
  22. margin-left: 550px;
  23. }
  24. .content{
  25. width: 600px;
  26. height: 500px;
  27. margin: 0 auto;
  28. }
  29. button{
  30. display: none;
  31. }
  32. .item:hover button{
  33. display: block;
  34. }
  35. .inp {
  36. width: 400px;
  37. height: 40px;
  38. position: absolute;
  39. top: 30px;
  40. left: 800px;
  41. border-radius: 5px;
  42. }
  43. h1{
  44. margin: 10px 0px;
  45. }
  46. .list>.item {
  47. width: 500px;
  48. height: 40px;
  49. border-radius: 5px;
  50. line-height: 40px;
  51. margin: 10px 0px;
  52. background-color: #fff;
  53. }
  54. .list>.item #ce {
  55. width: 10px;
  56. height: 40px;
  57. background-color: #629a9c;
  58. float: left;
  59. border-radius: 5px 0px 0px 5px;
  60. }
  61. .clear{
  62. margin-left: 360px;
  63. }
  64. .list>.item input {
  65. width: 20px;
  66. height: 20px;
  67. float: left;
  68. margin-top: 10px;
  69. margin-left: 10px;
  70. }
  71. .list>.item .inp2 {
  72. position: absolute;
  73. width: 200px;
  74. height: 30px;
  75. top: -8px;
  76. }
  77. .list>.item span {
  78. float: left;
  79. margin-left: 10px;
  80. }
  81. .list>.item button {
  82. width: 20px;
  83. height: 20px;
  84. line-height: 20px;
  85. float: right;
  86. margin-top: 10px;
  87. margin-right: 10px;
  88. border-radius: 50%;
  89. }

html部分

  1. <div id="app">
  2. <h1 class="h1">
  3. <span>ToDolist</span></h1>
  4. <div class="content">
  5. <input class="inp" type="text"
  6. placeholder="添加todo"
  7. v-model.trim="temp"
  8. @keyup.enter="addItem()" />
  9. <h1>正在进行</h1>
  10. <div class="list" >
  11. <div class="item" v-for="item in dolist" :key="item.title">
  12. <div id="ce"></div>
  13. <input type="checkbox" v-model="item.done" />
  14. <span
  15. @dblclick="editTemp=item.title;item.state=1"
  16. v-show="item.state==0">
  17. {{item.title}}</span>
  18. <input type="text" class="inp2"
  19. v-model="editTemp"
  20. v-show="item.state==1"
  21. @keyup.enter="item.title=editTemp;item.state=0;"
  22. @blur="item.title=editTemp;item.state=0;"
  23. @keyup.esc="item.state=0;editTemp=item.title;"
  24. v-focus="item.state==1"
  25. >
  26. <button type="button" @click="delItem(item)"></button>
  27. </div>
  28. </div>
  29. <h1>已经完成</h1>
  30. <div class="list">
  31. <div class="item" v-for="item in undolist" :key="item.title" style="opacity: .5;">
  32. <div id="ce"></div>
  33. <input type="checkbox" v-model="item.done" />
  34. <span @dblclick="editTemp=item.title;item.state=1"
  35. v-show="item.state==0">
  36. {{item.title}}</span>
  37. <input type="text" class="inp2"
  38. v-model="editTemp"
  39. v-show="item.state==1"
  40. @keyup.enter="item.title=editTemp;item.state=0;"
  41. @blur="item.title=editTemp;item.state=0;"
  42. @keyup.esc="item.state=0;editTemp=item.title;"
  43. v-focus="item.state==1"
  44. >
  45. <button type="button" @click="delItem(item)"></button>
  46. </div>
  47. </div>
  48. <p>
  49. <span style="color: #00FFFF;" v-if="list.length!=0"><b>{{list.length}}</b> Strip data</span>
  50. <span v-show="list.length!=0" @click="clear" class="clear" style="cursor: pointer; color: #00FFFF;">clear</span>
  51. </p>
  52. </div>
  53. </div>

js部分

  1. <script type="text/javascript">
  2. new Vue({
  3. el: "#app",
  4. watch:{
  5. "list":{
  6. handler(nval){
  7. localStorage.setItem("list",JSON.stringify(this.list))
  8. },
  9. deep:true
  10. }
  11. },
  12. computed:{
  13. dolist(){
  14. return this.list.filter(item=>!item.done);
  15. },
  16. undolist(){
  17. return this.list.filter(item=>item.done);
  18. }
  19. },
  20. data:{
  21. //通过本地存储来存储数据
  22. list:JSON.parse(localStorage.getItem("list")||"[]"),
  23. temp:"" ,
  24. editTemp:"",
  25. },
  26. methods:{
  27. //添加
  28. addItem(){
  29. var item = {title:this.temp,done:false,state:0}
  30. this.list.unshift(item);
  31. this.temp = "";
  32. },
  33. //删除
  34. delItem(item) {
  35. var ind = this.list.findIndex(value => value.title === item.title);
  36. this.list.splice(ind, 1);
  37. },
  38. clear:function(){
  39. this.list = []
  40. }
  41. },
  42. directives:{
  43. "focus":{
  44. update(el,binding){
  45. if(binding.value){el.focus()}
  46. }
  47. }
  48. }
  49. })
  50. </script>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/629228
推荐阅读
相关标签
  

闽ICP备14008679号