纪检监察网站建设的意义,能自己做生物实验的网站,iis发布php网站,html手机网站开发教程今天滴学习目标#xff01;#xff01;#xff01; 示例简介HTML内容主体区域输入框列表区域统计和清空 JS引入Vue.js库定义Vue实例el选项data选项methods选项 示例简介
HTML内容
本次实例讲解的是v-for、v-on、v-model来写这小小的实例#xff0c;下面是实例的效果图 示例简介HTML内容主体区域输入框列表区域统计和清空 JS引入Vue.js库定义Vue实例el选项data选项methods选项 示例简介
HTML内容
本次实例讲解的是v-for、v-on、v-model来写这小小的实例下面是实例的效果图想要代码在最后面的结尾处
主体区域
section idtodoapp这是整个记事本应用的容器
输入框
header classheader
包含一个标题 (h1记事本/h1) 和一个输入框 (input) 用于添加新的任务。输入框使用了Vue的v-model指令来双向绑定inputValue数据属性这意味着输入框的值会自动更新到inputValue同时如果inputValue改变输入框的值也会更新。keyup.enteradd是一个事件监听器当用户在输入框中按下Enter键时会调用add方法添加新任务。autofocusautofocus确保输入框在页面加载时自动获得焦点。autocompleteoff禁用浏览器的自动完成功能。placeholder请输入任务为输入框提供了一个占位符文本。
列表区域
section classmain
包含一个无序列表 (ul classtodo-list)用于显示所有任务。列表项 (li classtodo) 通过Vue的v-for(item,index) in list指令循环生成其中list是一个包含所有任务项的数组item是当前循环到的任务项index是当前项的索引。每个列表项内有一个.view的div包含任务的序号{{ index1 }}、任务描述{{ item }}和一个删除按钮button classdestroy点击删除按钮会调用remove(index)方法删除对应的任务。
统计和清空
footer classfooter
当任务列表不为空时v-show“list.length!0”显示统计信息和清空按钮。统计信息span classtodo-count显示当前任务的数量{{ list.length }}。清空按钮button classclear-completed点击时调用clear方法清除所有任务。
JS 引入Vue.js库
script srchttps://cdn.jsdelivr.net/npm/vue/dist/vue.js/script这行代码从jsdelivr CDN加载Vue.js的完整版本包含编译器和运行时。这是为了让Vue能够解析模板中的指令和组件。
定义Vue实例
var app new Vue({ // 选项
});这里创建了一个新的Vue实例并将其赋值给变量app。这个实例将管理之前HTML模板中idtodoapp的元素及其子元素。
el选项
el: #todoapp,这指定了Vue实例将要挂载的DOM元素。在这个例子中它挂载到idtodoapp的元素上。
data选项
data: { list: [], inputValue:
},这里定义了Vue实例的数据对象。list是一个数组用于存储任务项inputValue是一个字符串用于绑定到输入框的值。
methods选项
methods: { add: function () { this.list.push(this.inputValue); }, remove: function (index) { console.log(删除); console.log(index); this.list.splice(index, 1); }, clear: function () { this.list []; }
},这里定义了Vue实例的方法。
add方法将inputValue的值添加到list数组的末尾然后输入框的值会被清空因为v-model会自动更新。remove方法接受一个索引index作为参数并从list数组中移除对应位置的任务项。这里还包含了两个console.log语句用于调试它们会在控制台打印出删除和要删除的索引。clear方法将list数组重置为一个空数组从而清空所有任务项。 现在当用户在输入框中输入文本并按Enter键时add方法会被调用将文本添加到任务列表中。用户可以通过点击列表项旁边的删除按钮来调用remove方法删除任务按钮的click事件监听器会传递当前项的索引作为参数。最后用户可以通过点击清除按钮来调用clear方法清空所有任务。 请注意这段脚本应该放在HTML文档的底部紧接在包含Vue模板的元素的后面或者在一个确保DOM元素已经加载完毕的事件监听器中例如DOMContentLoaded事件。这样可以确保当Vue实例被创建时它要挂载的DOM元素已经存在。 代码
!DOCTYPE html
html langenheadmeta charsetUTF-8 /link relicon href/favicon.ico /meta nameviewport contentwidthdevice-width, initial-scale1.0 /title记事本/titlemeta http-equivcontent-type contenttext/html; charsetUTF-8 /meta namerobots contentnoindex, nofollow /meta namegooglebot contentnoindex, nofollow /meta nameviewport contentwidthdevice-width, initial-scale1 /!-- script srchttps://cdn.staticfile.net/vue/3.2.31/vue.global.min.js/scriptscript srchttps://cdn.staticfile.net/vue-router/4.2.4/vue-router.global.min.js/script --link relstylesheet typetext/css href../Vue/src/css/index.css /!-- script srchttps://cdn.staticfile.net/vue/3.2.36/vue.global.min.js/script --/headbody!-- 主体区域 --section idtodoapp!-- 输入框 --header classheaderh1记事本/h1input v-modelinputValue keyup.enteradd autofocusautofocus autocompleteoff placeholder请输入任务classnew-todo //header!-- 列表区域 --section classmainul classtodo-listli classtodo v-for(item,index) in listdiv classviewspan classindex{{ index1 }}./spanlabel{{ item }}/labelbutton classdestroy clickremove(index)/button/div/li/ul/section!-- 统计和清空 --footer classfooter v-showlist.length!0span classtodo-count v-iflist.length!0strong{{ list.length }}/strong条数据/spanbutton v-showlist.length!0 classclear-completed clickclear清除/button/footer/section!-- 底部 --!-- 开发环境版本包含了有帮助的命令行警告 --script srchttps://cdn.jsdelivr.net/npm/vue/dist/vue.js/scriptscriptvar app new Vue({el: #todoapp,data: {list: [],inputValue: },methods: {add: function () {this.list.push(this.inputValue);},remove: function (index) {console.log(删除);console.log(index);this.list.splice(index, 1);},clear: function () {this.list [];}},})/script!-- div idapp/div --!-- script typemodule src/src/main.js/script --/body
/htmlCSS
html,
body {margin: 0;padding: 0;
}
body {background: #fff;
}
button {margin: 0;padding: 0;border: 0;background: none;font-size: 100%;vertical-align: baseline;font-family: inherit;font-weight: inherit;color: inherit;-webkit-appearance: none;appearance: none;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;
}body {font: 14px Helvetica Neue, Helvetica, Arial, sans-serif;line-height: 1.4em;background: #f5f5f5;color: #4d4d4d;min-width: 230px;max-width: 550px;margin: 0 auto;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;font-weight: 300;
}:focus {outline: 0;
}.hidden {display: none;
}#todoapp {background: #fff;margin: 180px 0 40px 0;position: relative;box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
}#todoapp input::-webkit-input-placeholder {font-style: italic;font-weight: 300;color: #e6e6e6;
}#todoapp input::-moz-placeholder {font-style: italic;font-weight: 300;color: #e6e6e6;
}#todoapp input::input-placeholder {font-style: italic;font-weight: 300;color: gray;
}#todoapp h1 {position: absolute;top: -160px;width: 100%;font-size: 60px;font-weight: 100;text-align: center;color: rgba(175, 47, 47, .8);-webkit-text-rendering: optimizeLegibility;-moz-text-rendering: optimizeLegibility;text-rendering: optimizeLegibility;
}.new-todo,
.edit {position: relative;margin: 0;width: 100%;font-size: 24px;font-family: inherit;font-weight: inherit;line-height: 1.4em;border: 0;color: inherit;padding: 6px;border: 1px solid #999;box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2);box-sizing: border-box;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;
}.new-todo {padding: 16px;border: none;background: rgba(0, 0, 0, 0.003);box-shadow: inset 0 -2px 1px rgba(0, 0, 0, 0.03);
}.main {position: relative;z-index: 2;border-top: 1px solid #e6e6e6;
}.toggle-all {width: 1px;height: 1px;border: none; /* Mobile Safari */opacity: 0;position: absolute;right: 100%;bottom: 100%;
}.toggle-all label {width: 60px;height: 34px;font-size: 0;position: absolute;top: -52px;left: -13px;-webkit-transform: rotate(90deg);transform: rotate(90deg);
}.toggle-all label:before {content: ❯;font-size: 22px;color: #e6e6e6;padding: 10px 27px 10px 27px;
}.toggle-all:checked label:before {color: #737373;
}.todo-list {margin: 0;padding: 0;list-style: none;max-height: 420px;overflow: auto;
}.todo-list li {position: relative;font-size: 24px;border-bottom: 1px solid #ededed;height: 60px;box-sizing: border-box;
}.todo-list li:last-child {border-bottom: none;
}.todo-list .view .index {position: absolute;color: gray;left: 10px;top: 20px;font-size: 16px;
}.todo-list li .toggle {text-align: center;width: 40px;/* auto, since non-WebKit browsers doesnt support input styling */height: auto;position: absolute;top: 0;bottom: 0;margin: auto 0;border: none; /* Mobile Safari */-webkit-appearance: none;appearance: none;
}.todo-list li .toggle {opacity: 0;
}.todo-list li .toggle label {/*Firefox requires # to be escaped - https://bugzilla.mozilla.org/show_bug.cgi?id922433IE 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/*/background-image: url(data:image/svgxml;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);background-repeat: no-repeat;background-position: center left;
}.todo-list li .toggle:checked label {background-image: url(data:image/svgxml;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);
}.todo-list li label {word-break: break-all;padding: 15px 15px 15px 60px;display: block;line-height: 1.2;transition: color 0.4s;
}.todo-list li.completed label {color: #d9d9d9;text-decoration: line-through;
}.todo-list li .destroy {display: none;position: absolute;top: 0;right: 10px;bottom: 0;width: 40px;height: 40px;margin: auto 0;font-size: 30px;color: #cc9a9a;margin-bottom: 11px;transition: color 0.2s ease-out;
}.todo-list li .destroy:hover {color: #af5b5e;
}.todo-list li .destroy:after {content: ×;
}.todo-list li:hover .destroy {display: block;
}.todo-list li .edit {display: none;
}.todo-list li.editing:last-child {margin-bottom: -1px;
}.footer {color: #777;padding: 10px 15px;height: 20px;text-align: center;border-top: 1px solid #e6e6e6;
}.footer:before {content: ;position: absolute;right: 0;bottom: 0;left: 0;height: 50px;overflow: hidden;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2), 0 8px 0 -3px #f6f6f6,0 9px 1px -3px rgba(0, 0, 0, 0.2), 0 16px 0 -6px #f6f6f6,0 17px 2px -6px rgba(0, 0, 0, 0.2);
}.todo-count {float: left;text-align: left;
}.todo-count strong {font-weight: 300;
}.filters {margin: 0;padding: 0;list-style: none;position: absolute;right: 0;left: 0;
}.filters li {display: inline;
}.filters li a {color: inherit;margin: 3px;padding: 3px 7px;text-decoration: none;border: 1px solid transparent;border-radius: 3px;
}.filters li a:hover {border-color: rgba(175, 47, 47, 0.1);
}.filters li a.selected {border-color: rgba(175, 47, 47, 0.2);
}.clear-completed,
html .clear-completed:active {float: right;position: relative;line-height: 20px;text-decoration: none;cursor: pointer;
}.clear-completed:hover {text-decoration: underline;
}.info {margin: 50px auto 0;color: #bfbfbf;font-size: 15px;text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);text-align: center;
}.info p {line-height: 1;
}.info a {color: inherit;text-decoration: none;font-weight: 400;
}.info a:hover {text-decoration: underline;
}/*Hack to remove background from Mobile Safari.Cant use it globally since it destroys checkboxes in Firefox
*/
media screen and (-webkit-min-device-pixel-ratio: 0) {.toggle-all,.todo-list li .toggle {background: none;}.todo-list li .toggle {height: 40px;}
}media (max-width: 430px) {.footer {height: 50px;}.filters {bottom: 10px;}
}