功能

  1. 按回车键可往表中新增事件
  2. 可以删除已添加的事件
  3. 可以一键清空表中所有的事件
  4. 有统计事件的总数的功能

    效果图

    image.png

代码

  1. <html>
  2. <head>
  3. <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  4. <title>小X记事本</title>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  6. <meta name="robots" content="noindex, nofollow" />
  7. <meta name="googlebot" content="noindex, nofollow" />
  8. <meta name="viewport" content="width=device-width, initial-scale=1" />
  9. <link rel="stylesheet" type="text/css" href="./css/index.css" />
  10. </head>
  11. <body>
  12. <!-- 主体区域 -->
  13. <section id="todoapp">
  14. <!-- 输入框 -->
  15. <header class="header">
  16. <h1>小X记事本</h1>
  17. <input v-model="inputValue" @keyup.enter="add" autofocus="autofocus" autocomplete="off" placeholder="请输入任务"
  18. class="new-todo" >
  19. </header>
  20. <!-- 列表区域 -->
  21. <section class="main">
  22. <ul class="todo-list">
  23. <li class="todo" v-for="(item,index) in list">
  24. <div class="view">
  25. <span class="index">{{ index+1 }}.</span>
  26. <label>{{ item }}</label>
  27. <button class="destroy" @click="remove(index)"></button>
  28. </div>
  29. </li>
  30. </ul>
  31. </section>
  32. <!-- 统计和清空 -->
  33. <footer class="footer" >
  34. <!--
  35. 这里用v-if和v-show都行,根据表达式的真值切换元素的显示和隐藏。
  36. v-show:本质是通过操纵dom元素来切换显示状态,当表达式为true时,元素存在于dom树中,当为false时元素从dom树中移除
  37. v-if:设置display的值来控制元素的显示与隐藏
  38. -->
  39. <span class="todo-count" v-if="list.length!=0">
  40. <!-- 基于数据的开发方式--将标签内的元素用差值表达式换成是数组的长度即可 -->
  41. <strong>{{ list.length }}</strong> items left
  42. </span>
  43. <button class="clear-completed" @click="clear" v-if="list.length!=0">
  44. Clear
  45. </button>
  46. </footer>
  47. </section>
  48. <!-- 开发环境版本,包含了有帮助的命令行警告 -->
  49. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  50. <script>
  51. var app = new Vue({
  52. el: "#todoapp",
  53. data: {
  54. list: ["写代码", "吃饭饭", "睡觉觉"],
  55. inputValue: "好好学习,天天向上"
  56. },
  57. methods: {
  58. add: function () {
  59. this.list.push(this.inputValue);
  60. },
  61. remove:function(index) {
  62. //splice--从index这个位置开始删除1个元素
  63. this.list.splice(index,1);
  64. },
  65. clear:function() {
  66. //清空即让list数组为空即可
  67. this.list=[];
  68. }
  69. },
  70. })
  71. </script>
  72. </body>
  73. </html>
  1. html,
  2. body {
  3. margin: 0;
  4. padding: 0;
  5. }
  6. body {
  7. background: #fff;
  8. }
  9. button {
  10. margin: 0;
  11. padding: 0;
  12. border: 0;
  13. background: none;
  14. font-size: 100%;
  15. vertical-align: baseline;
  16. font-family: inherit;
  17. font-weight: inherit;
  18. color: inherit;
  19. -webkit-appearance: none;
  20. appearance: none;
  21. -webkit-font-smoothing: antialiased;
  22. -moz-osx-font-smoothing: grayscale;
  23. }
  24. body {
  25. font: 14px "Helvetica Neue", Helvetica, Arial, sans-serif;
  26. line-height: 1.4em;
  27. background: #f5f5f5;
  28. color: #4d4d4d;
  29. min-width: 230px;
  30. max-width: 550px;
  31. margin: 0 auto;
  32. -webkit-font-smoothing: antialiased;
  33. -moz-osx-font-smoothing: grayscale;
  34. font-weight: 300;
  35. }
  36. :focus {
  37. outline: 0;
  38. }
  39. .hidden {
  40. display: none;
  41. }
  42. #todoapp {
  43. background: #fff;
  44. margin: 180px 0 40px 0;
  45. position: relative;
  46. box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
  47. }
  48. #todoapp input::-webkit-input-placeholder {
  49. font-style: italic;
  50. font-weight: 300;
  51. color: #e6e6e6;
  52. }
  53. #todoapp input::-moz-placeholder {
  54. font-style: italic;
  55. font-weight: 300;
  56. color: #e6e6e6;
  57. }
  58. #todoapp input::input-placeholder {
  59. font-style: italic;
  60. font-weight: 300;
  61. color: gray;
  62. }
  63. #todoapp h1 {
  64. position: absolute;
  65. top: -160px;
  66. width: 100%;
  67. font-size: 60px;
  68. font-weight: 100;
  69. text-align: center;
  70. color: rgba(175, 47, 47, .8);
  71. -webkit-text-rendering: optimizeLegibility;
  72. -moz-text-rendering: optimizeLegibility;
  73. text-rendering: optimizeLegibility;
  74. }
  75. .new-todo,
  76. .edit {
  77. position: relative;
  78. margin: 0;
  79. width: 100%;
  80. font-size: 24px;
  81. font-family: inherit;
  82. font-weight: inherit;
  83. line-height: 1.4em;
  84. border: 0;
  85. color: inherit;
  86. padding: 6px;
  87. border: 1px solid #999;
  88. box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
  89. box-sizing: border-box;
  90. -webkit-font-smoothing: antialiased;
  91. -moz-osx-font-smoothing: grayscale;
  92. }
  93. .new-todo {
  94. padding: 16px;
  95. border: none;
  96. background: rgba(0, 0, 0, 0.003);
  97. box-shadow: inset 0 -2px 1px rgba(0, 0, 0, 0.03);
  98. }
  99. .main {
  100. position: relative;
  101. z-index: 2;
  102. border-top: 1px solid #e6e6e6;
  103. }
  104. .toggle-all {
  105. width: 1px;
  106. height: 1px;
  107. border: none; /* Mobile Safari */
  108. opacity: 0;
  109. position: absolute;
  110. right: 100%;
  111. bottom: 100%;
  112. }
  113. .toggle-all + label {
  114. width: 60px;
  115. height: 34px;
  116. font-size: 0;
  117. position: absolute;
  118. top: -52px;
  119. left: -13px;
  120. -webkit-transform: rotate(90deg);
  121. transform: rotate(90deg);
  122. }
  123. .toggle-all + label:before {
  124. content: "❯";
  125. font-size: 22px;
  126. color: #e6e6e6;
  127. padding: 10px 27px 10px 27px;
  128. }
  129. .toggle-all:checked + label:before {
  130. color: #737373;
  131. }
  132. .todo-list {
  133. margin: 0;
  134. padding: 0;
  135. list-style: none;
  136. max-height: 420px;
  137. overflow: auto;
  138. }
  139. .todo-list li {
  140. position: relative;
  141. font-size: 24px;
  142. border-bottom: 1px solid #ededed;
  143. height: 60px;
  144. box-sizing: border-box;
  145. }
  146. .todo-list li:last-child {
  147. border-bottom: none;
  148. }
  149. .todo-list .view .index {
  150. position: absolute;
  151. color: gray;
  152. left: 10px;
  153. top: 20px;
  154. font-size: 16px;
  155. }
  156. .todo-list li .toggle {
  157. text-align: center;
  158. width: 40px;
  159. /* auto, since non-WebKit browsers doesn't support input styling */
  160. height: auto;
  161. position: absolute;
  162. top: 0;
  163. bottom: 0;
  164. margin: auto 0;
  165. border: none; /* Mobile Safari */
  166. -webkit-appearance: none;
  167. appearance: none;
  168. }
  169. .todo-list li .toggle {
  170. opacity: 0;
  171. }
  172. .todo-list li .toggle + label {
  173. /*
  174. Firefox requires `#` to be escaped - https://bugzilla.mozilla.org/show_bug.cgi?id=922433
  175. IE and Edge requires *everything* to be escaped to render, so we do that instead of just the `#` - https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/7157459/
  176. */
  177. background-image: url("data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23ededed%22%20stroke-width%3D%223%22/%3E%3C/svg%3E");
  178. background-repeat: no-repeat;
  179. background-position: center left;
  180. }
  181. .todo-list li .toggle:checked + label {
  182. background-image: url("data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23bddad5%22%20stroke-width%3D%223%22/%3E%3Cpath%20fill%3D%22%235dc2af%22%20d%3D%22M72%2025L42%2071%2027%2056l-4%204%2020%2020%2034-52z%22/%3E%3C/svg%3E");
  183. }
  184. .todo-list li label {
  185. word-break: break-all;
  186. padding: 15px 15px 15px 60px;
  187. display: block;
  188. line-height: 1.2;
  189. transition: color 0.4s;
  190. }
  191. .todo-list li.completed label {
  192. color: #d9d9d9;
  193. text-decoration: line-through;
  194. }
  195. .todo-list li .destroy {
  196. display: none;
  197. position: absolute;
  198. top: 0;
  199. right: 10px;
  200. bottom: 0;
  201. width: 40px;
  202. height: 40px;
  203. margin: auto 0;
  204. font-size: 30px;
  205. color: #cc9a9a;
  206. margin-bottom: 11px;
  207. transition: color 0.2s ease-out;
  208. }
  209. .todo-list li .destroy:hover {
  210. color: #af5b5e;
  211. }
  212. .todo-list li .destroy:after {
  213. content: "×";
  214. }
  215. .todo-list li:hover .destroy {
  216. display: block;
  217. }
  218. .todo-list li .edit {
  219. display: none;
  220. }
  221. .todo-list li.editing:last-child {
  222. margin-bottom: -1px;
  223. }
  224. .footer {
  225. color: #777;
  226. padding: 10px 15px;
  227. height: 20px;
  228. text-align: center;
  229. border-top: 1px solid #e6e6e6;
  230. }
  231. .footer:before {
  232. content: "";
  233. position: absolute;
  234. right: 0;
  235. bottom: 0;
  236. left: 0;
  237. height: 50px;
  238. overflow: hidden;
  239. box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2), 0 8px 0 -3px #f6f6f6,
  240. 0 9px 1px -3px rgba(0, 0, 0, 0.2), 0 16px 0 -6px #f6f6f6,
  241. 0 17px 2px -6px rgba(0, 0, 0, 0.2);
  242. }
  243. .todo-count {
  244. float: left;
  245. text-align: left;
  246. }
  247. .todo-count strong {
  248. font-weight: 300;
  249. }
  250. .filters {
  251. margin: 0;
  252. padding: 0;
  253. list-style: none;
  254. position: absolute;
  255. right: 0;
  256. left: 0;
  257. }
  258. .filters li {
  259. display: inline;
  260. }
  261. .filters li a {
  262. color: inherit;
  263. margin: 3px;
  264. padding: 3px 7px;
  265. text-decoration: none;
  266. border: 1px solid transparent;
  267. border-radius: 3px;
  268. }
  269. .filters li a:hover {
  270. border-color: rgba(175, 47, 47, 0.1);
  271. }
  272. .filters li a.selected {
  273. border-color: rgba(175, 47, 47, 0.2);
  274. }
  275. .clear-completed,
  276. html .clear-completed:active {
  277. float: right;
  278. position: relative;
  279. line-height: 20px;
  280. text-decoration: none;
  281. cursor: pointer;
  282. }
  283. .clear-completed:hover {
  284. text-decoration: underline;
  285. }
  286. .info {
  287. margin: 50px auto 0;
  288. color: #bfbfbf;
  289. font-size: 15px;
  290. text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
  291. text-align: center;
  292. }
  293. .info p {
  294. line-height: 1;
  295. }
  296. .info a {
  297. color: inherit;
  298. text-decoration: none;
  299. font-weight: 400;
  300. }
  301. .info a:hover {
  302. text-decoration: underline;
  303. }
  304. /*
  305. Hack to remove background from Mobile Safari.
  306. Can't use it globally since it destroys checkboxes in Firefox
  307. */
  308. @media screen and (-webkit-min-device-pixel-ratio: 0) {
  309. .toggle-all,
  310. .todo-list li .toggle {
  311. background: none;
  312. }
  313. .todo-list li .toggle {
  314. height: 40px;
  315. }
  316. }
  317. @media (max-width: 430px) {
  318. .footer {
  319. height: 50px;
  320. }
  321. .filters {
  322. bottom: 10px;
  323. }
  324. }