经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » Vue.js » 查看文章
vue实现记事本案例
来源:jb51  时间:2022/4/11 14:27:12  对本文有异议

本文实例为大家分享了vue实现记事本案例的具体代码,供大家参考,具体内容如下

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. ?
  4. <head>
  5. ? ? <meta charset="UTF-8">
  6. ? ? <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. ? ? <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. ? ? <title>Document</title>
  9. ? ? <!-- 引入样式 -->
  10. ? ? <link rel="stylesheet" href="./css/index.css">
  11. </head>
  12. ?
  13. <body>
  14. ? ? <!--?
  15. ? ? 1.用户输入待办事项,回车后添加到“正在进行”,并清空文本框 ?
  16. ? ? 2.在“正在进行”列表中单击列表项,添加到 已完成 列表 ?
  17. ? ? 3.在“已经完成”列表中单击列表项,添加到 正在进行 列表?
  18. ? ? 4.在响应列表项中点击 删除 ?删除 该项目。
  19. ? ?-->
  20. ? ? <div id="app">
  21. ? ? ? ? <header>
  22. ? ? ? ? ? ? <section>
  23. ? ? ? ? ? ? ? ? <label for="title"></label>
  24. ? ? ? ? ? ? ? ? <input type="text" v-model="thing" placeholder="添加ToDo" required="required" autocomplete="off" @keydown.13="add">
  25. ? ? ? ? ? ? </section>
  26. ? ? ? ? </header>
  27. ? ? ? ? <section>
  28. ? ? ? ? ? ? <h2>正在进行<span>{{ongoing.length}}</span></h2>
  29. ? ? ? ? ? ? <ol id="todolist" class="demo-box">
  30. ? ? ? ? ? ? ? ? <li v-for="(item,index) in ongoing" :key="item.id">
  31. ? ? ? ? ? ? ? ? ? ? <input type="checkbox" @click="addToDone(index)"> {{item.title}}
  32. ? ? ? ? ? ? ? ? ? ? <button @click="delGoing(index)">删除</button>
  33. ? ? ? ? ? ? ? ? </li>
  34. ? ? ? ? ? ? </ol>
  35. ? ? ? ? ? ? <h2>已完成<span>{{done.length}}</span></h2>
  36. ? ? ? ? ? ? <ul id="donelist">
  37. ? ? ? ? ? ? ? ? <li v-for="(item,index) in done" :key="item.id">
  38. ? ? ? ? ? ? ? ? ? ? <input type="checkbox" checked @click="addToGoing(index)"> {{item.title}}
  39. ? ? ? ? ? ? ? ? ? ? <button @click="delDone(index)">删除</button>
  40. ? ? ? ? ? ? ? ? </li>
  41. ? ? ? ? ? ? </ul>
  42. ? ? ? ? </section>
  43. ? ? </div>
  44. ? ? <footer>
  45. ? ? ? ? Copyright &copy; 2021 todolist.cn
  46. ? ? </footer>
  47. ? ? <script src="../vue.js"></script>
  48. ? ? <script>
  49. ? ? ? ? new Vue({
  50. ? ? ? ? ? ? el: "#app",
  51. ? ? ? ? ? ? data: {
  52. ? ? ? ? ? ? ? ? id: 4,
  53. ? ? ? ? ? ? ? ? //存储用户输入的信息
  54. ? ? ? ? ? ? ? ? thing: "",
  55. ? ? ? ? ? ? ? ? /* 正在进行 列表 */
  56. ? ? ? ? ? ? ? ? ongoing: [{
  57. ? ? ? ? ? ? ? ? ? ? id: 1,
  58. ? ? ? ? ? ? ? ? ? ? title: "吃饭"
  59. ? ? ? ? ? ? ? ? }, {
  60. ? ? ? ? ? ? ? ? ? ? id: 2,
  61. ? ? ? ? ? ? ? ? ? ? title: "睡觉"
  62. ? ? ? ? ? ? ? ? }],
  63. ? ? ? ? ? ? ? ? //已经完成 列表
  64. ? ? ? ? ? ? ? ? done: [{
  65. ? ? ? ? ? ? ? ? ? ? id: 3,
  66. ? ? ? ? ? ? ? ? ? ? title: "打豆豆"
  67. ? ? ? ? ? ? ? ? }]
  68. ? ? ? ? ? ? },
  69. ? ? ? ? ? ? methods: {
  70. ? ? ? ? ? ? ? ? //添加到待办事项
  71. ? ? ? ? ? ? ? ? add() {
  72. ? ? ? ? ? ? ? ? ? ? //组装一个对象,将对象添加到ongoing数组中。
  73. ? ? ? ? ? ? ? ? ? ? let obj = {
  74. ? ? ? ? ? ? ? ? ? ? ? ? id: this.id,
  75. ? ? ? ? ? ? ? ? ? ? ? ? title: this.thing
  76. ? ? ? ? ? ? ? ? ? ? };
  77. ? ? ? ? ? ? ? ? ? ? //新的对象产生,id自增,防止id重复。
  78. ? ? ? ? ? ? ? ? ? ? this.id++;
  79. ? ? ? ? ? ? ? ? ? ? /* 把获取到的值添加到待办事项 */
  80. ? ? ? ? ? ? ? ? ? ? this.ongoing.push(obj);
  81. ? ? ? ? ? ? ? ? ? ? //将thing的值设置为空,则输入框自动清空
  82. ? ? ? ? ? ? ? ? ? ? this.thing = "";
  83. ? ? ? ? ? ? ? ? },
  84. ? ? ? ? ? ? ? ? //添加到已经完成
  85. ? ? ? ? ? ? ? ? addToDone(index) {
  86. ? ? ? ? ? ? ? ? ? ? //将点击的数据 从ongoing 删除,添加到 Done中
  87. ? ? ? ? ? ? ? ? ? ? //splice(index,1)从index开始,删除一个元素。 splice会返回被删除的元素组成的数组。
  88. ? ? ? ? ? ? ? ? ? ? this.done.push(this.ongoing.splice(index, 1)[0])
  89. ? ? ? ? ? ? ? ? },
  90. ? ? ? ? ? ? ? ? /* 添加到正在进行 */
  91. ? ? ? ? ? ? ? ? addToGoing(index) {
  92. ? ? ? ? ? ? ? ? ? ? this.ongoing.push(this.done.splice(index, 1)[0])
  93. ? ? ? ? ? ? ? ? },
  94. ? ? ? ? ? ? ? ? /* 从正在进行中删除 */
  95. ? ? ? ? ? ? ? ? delGoing(index) {
  96. ? ? ? ? ? ? ? ? ? ? this.ongoing.splice(index, 1)
  97. ? ? ? ? ? ? ? ? },
  98. ? ? ? ? ? ? ? ? /* 从已经完成中删除 */
  99. ? ? ? ? ? ? ? ? delDone(index) {
  100. ? ? ? ? ? ? ? ? ? ? this.done.splice(index, 1)
  101. ? ? ? ? ? ? ? ? }
  102. ? ? ? ? ? ? }
  103. ? ? ? ? })
  104. ? ? </script>
  105. </body>
  106. ?
  107. </html>

样式部分

  1. body {
  2. ? margin: 0;
  3. ? padding: 0;
  4. ? font-size: 16px;
  5. ? background: #CDCDCD;
  6. }
  7. ?
  8. header {
  9. ? height: 50px;
  10. ? background: #333;
  11. ? background: rgba(47, 47, 47, 0.98);
  12. }
  13. ?
  14. section {
  15. ? margin: 0 auto;
  16. }
  17. ?
  18. label {
  19. ? float: left;
  20. ? width: 100px;
  21. ? line-height: 50px;
  22. ? color: #DDD;
  23. ? font-size: 24px;
  24. ? cursor: pointer;
  25. ? font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  26. }
  27. ?
  28. header input {
  29. ? float: right;
  30. ? width: 60%;
  31. ? height: 24px;
  32. ? margin-top: 12px;
  33. ? text-indent: 10px;
  34. ? border-radius: 5px;
  35. ? box-shadow: 0 1px 0 rgba(255, 255, 255, 0.24), 0 1px 6px rgba(0, 0, 0, 0.45) inset;
  36. ? border: none
  37. }
  38. ?
  39. input:focus {
  40. ? outline-width: 0
  41. }
  42. ?
  43. h2 {
  44. ? position: relative;
  45. }
  46. ?
  47. span {
  48. ? position: absolute;
  49. ? top: 2px;
  50. ? right: 5px;
  51. ? display: inline-block;
  52. ? padding: 0 5px;
  53. ? height: 20px;
  54. ? border-radius: 20px;
  55. ? background: #E6E6FA;
  56. ? line-height: 22px;
  57. ? text-align: center;
  58. ? color: #666;
  59. ? font-size: 14px;
  60. }
  61. ?
  62. ol,
  63. ul {
  64. ? padding: 0;
  65. ? list-style: none;
  66. }
  67. ?
  68. li input {
  69. ? position: absolute;
  70. ? top: 2px;
  71. ? left: 10px;
  72. ? width: 22px;
  73. ? height: 22px;
  74. ? cursor: pointer;
  75. }
  76. ?
  77. p {
  78. ? margin: 0;
  79. }
  80. ?
  81. li p input {
  82. ? top: 3px;
  83. ? left: 40px;
  84. ? width: 70%;
  85. ? height: 20px;
  86. ? line-height: 14px;
  87. ? text-indent: 5px;
  88. ? font-size: 14px;
  89. }
  90. ?
  91. li {
  92. ? height: 32px;
  93. ? line-height: 32px;
  94. ? background: #fff;
  95. ? position: relative;
  96. ? margin-bottom: 10px;
  97. ? padding: 0 45px;
  98. ? border-radius: 3px;
  99. ? border-left: 5px solid #629A9C;
  100. ? box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07);
  101. }
  102. ?
  103. ol li {
  104. ? cursor: move;
  105. }
  106. ?
  107. ul li {
  108. ? border-left: 5px solid #999;
  109. ? opacity: 0.5;
  110. }
  111. ?
  112. li a {
  113. ? position: absolute;
  114. ? top: 2px;
  115. ? right: 5px;
  116. ? display: inline-block;
  117. ? width: 14px;
  118. ? height: 12px;
  119. ? border-radius: 14px;
  120. ? border: 6px double #FFF;
  121. ? background: #CCC;
  122. ? line-height: 14px;
  123. ? text-align: center;
  124. ? color: #FFF;
  125. ? font-weight: bold;
  126. ? font-size: 14px;
  127. ? cursor: pointer;
  128. }
  129. ?
  130. li button{
  131. ? position: absolute;
  132. ? right: 10px;
  133. ? top: 50%;
  134. ? transform: translateY(-50%);
  135. }
  136. ?
  137. footer {
  138. ? color: #666;
  139. ? font-size: 14px;
  140. ? text-align: center;
  141. }
  142. ?
  143. @media screen and (max-device-width: 620px) {
  144. ? section {
  145. ? ? ?width: 96%;
  146. ? ? ?padding: 0 2%;
  147. ? }
  148. }
  149. ?
  150. @media screen and (min-width: 620px) {
  151. ? section {
  152. ? ? ?width: 600px;
  153. ? ? ?padding: 0 10px;
  154. ? }
  155. }

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

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号