current position:Home>Vue - make todolist
Vue - make todolist
2022-01-27 01:26:53 【Nanchen_ forty-two】
The effect is as follows :
Implementation code :
HTML part :
<div id="todo" class="todo">
<div class="header">
<section>
<!-- input part -->
<label for="title">ToDoList</label>
<input type="text" name="title" placeholder=" Please enter your to-do list ........." required="required" autocomplete="off"
v-model="title" v-on:keypress.enter="addTodo">
</section>
</div>
<section>
<!-- The first half -->
<h2> The first half <span id="todoCount" class="count">{
{firstList.length}}</span></h2>
<ol id="todoList">
<li v-for="(item,index) in firstList">
<input type="checkbox" v-on:click.prevent="checkedTodo(index)" v-model="item.done">
<p>{
{item.title}}</p>
<a href="###" v-on:click="deleteABtn1(index)">-</a>
</li>
</ol>
<!-- The second part of -->
<h2> The second part of <span id="doneCount" class="count">{
{doneList.length}}</span></h2>
<ol id="doneList">
<li v-for="(item,index) in doneList">
<input type="checkbox" v-on:click.prevent="checkedDone(index)" v-model="item.done">
<p>{
{item.title}}</p>
<a href="###" v-on:click="deleteABtn2(index)">-</a>
</li>
</ol>
</section>
<p class="footer">footer</p>
</div>
CSS part :
* {
margin: 0;
padding: 0;
}
body {
font-size: 16px;
background: #cdcdcd;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.header {
height: 50px;
background: rgba(47, 47, 47, 0.98);
}
section {
max-width: 620px;
margin: 0 auto;
padding: 0 10px;
}
label {
float: left;
width: 100px;
line-height: 50px;
color: #ddd;
font-size: 24px;
cursor: pointer;
}
.header input {
float: right;
width: 60%;
height: 24px;
margin-top: 12px;
text-indent: 10px;
border-top-left-radius: 5px;
border-radius: 5px;
box-shadow: 0 1px 0 rgba(255, 255, 255, 0.24), 0 1px 6px rgba(0, 0, 0, 0.45) inset;
outline: none;
border: none;
}
h2 {
position: relative;
margin: 26px 0;
}
h2 .count {
position: absolute;
top: 2px;
right: 5px;
display: inline-block;
padding: 0 5px;
height: 20px;
border-radius: 20px;
background: #e6e6fa;
line-height: 22px;
text-align: center;
color: #666;
font-size: 14px;
}
ol {
margin: 28px 0 32px;
}
ol,
ul {
list-style-type: none;
}
li {
height: 32px;
line-height: 32px;
background: #fff;
position: relative;
margin-bottom: 10px;
padding: 0 48px;
border-radius: 3px;
border-left: 5px solid #629a9c;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07);
}
li input {
position: absolute;
top: 6px;
left: 22px;
width: 22px;
height: 22px;
cursor: pointer;
}
li p {
line-height: 34px;
}
li a {
position: absolute;
top: 4px;
right: 5px;
display: inline-block;
width: 14px;
height: 12px;
border-radius: 14px;
border: 6px double #fff;
background: #ccc;
line-height: 12px;
text-align: center;
color: #fff;
font-weight: bold;
font-size: 14px;
cursor: pointer;
}
#doneList li {
border-left: 5px solid #999;
opacity: 0.5;
}
.footer {
font-size: 14px;
text-align: center;
color: #666;
}
@media only screen and (max-width: 400px){
.header input{
width: 52%;
}
}
script part :
var todo = new Vue({
el: "#todo",
data: {
title: '',
// Set up firstList Empty array
firstList: [],
// Set up doneList An empty array is used to store data locally
doneList: [],
},
// Before loading :
beforeMount() {
// load localstorage
var storage = window.localStorage;
// If you get todo When not null
if (storage.getItem("todo") !== null) {
// Parse from string json object , And get the data todo
this.firstList = JSON.parse(storage.getItem("todo"));
}
if (storage.getItem("done") !== null) {
this.doneList = JSON.parse(storage.getItem("done"));
}
},
methods: {
// Trigger when clicked
addTodo() {
// If input If the box is empty, a pop-up window will pop up
if (this.title === '') {
return alert(' You have not entered the data you need to store !!');
}
// If there's something, then The upper part of span The new data obtained will be placed in the first position of the array
this.firstList.unshift({
// Give Way input Medium title Binding
title: this.title,
// hold done The button is set to off
done: false
});
// Remember to clear... After entering input Value in box
this.title = '';
// Store data locally
this.setLocalStorage();
},
// When you click the delete button in the first part a This event is triggered when
deleteABtn1(index) {
// Delete the stored value
this.firstList.splice(index, 1);
// After deletion, store the rest locally
this.setLocalStorage();
},
// When you click the delete button in the second part a Trigger event
deleteABtn2(index) {
// Click to delete the corresponding part
this.doneList.splice(index, 1);
// Store
this.setLocalStorage();
},
// Click... In the first part input Trigger event
checkedTodo(index) {
// span The index of the number in done for true
// firstList.children[0].checked = 'checked'
this.firstList[index].done = true;
// hold firstList Put it in doneList Foremost
this.doneList.unshift(this.firstList[index]);
// And then the top half span The index of is also deleted
this.firstList.splice(index, 1);
// And store it
this.setLocalStorage();
},
// After the second half appears input box ( That is, in the checked box ) Set the click event
// The main purpose is to change the check box to closed state after clicking , And put it in the top half , Delete your location
checkedDone(index) {
// The lower part of span Index of numbers done Value is set to flase
this.doneList[index].done = false;
// Put the lower half at the front of the upper half
this.firstList.unshift(this.doneList[index]);
// The lower part of span Click to delete the current value
this.doneList.splice(index, 1);
this.setLocalStorage();
},
setLocalStorage() {
// Storage localstorage
var storage = window.localStorage;
// take JavaScript Value to JSON character string
storage.setItem("todo", JSON.stringify(this.firstList));
storage.setItem("done", JSON.stringify(this.doneList));
}
}
});
copyright notice
author[Nanchen_ forty-two],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270126513661.html
The sidebar is recommended
- Spring IOC container loading process
- [thinking] the difference between singleton mode and static method - object-oriented programming
- Hadoop environment setup (MySQL environment configuration)
- 10 minutes, using node JS creates a real-time early warning system for bad weather!
- Git tool
- Force deduction algorithm - 92 Reverse linked list II
- What is the sub problem of dynamic programming?
- C / C + +: static keyword summary
- Idea does not have the artifacts option when configuring Tomcat
- Anaconda can't open it
guess what you like
-
I don't know how to start this
-
Matlab simulation of transportation optimization algorithm based on PSO
-
MySQL slow log optimization
-
[Vue] as the window is stretched (larger, smaller, wider and higher), the text will not be displayed
-
Popular Linux distributions for embedded computing
-
Suzhou computer research
-
After installing SSL Certificate in Windows + tomcat, the domain name request is not successful. Please answer!!
-
Implementation time output and greetings of jQuery instance
-
The 72 year old uncle became popular. Wu Jing and Guo fan made his story into a film, which made countless dreamers blush
-
How to save computer research
Random recommended
- Springboot implements excel import and export, which is easy to use, and poi can be thrown away
- The final examination subjects of a class are mathematical programming, and the scores are sorted and output from high to low
- Two pronged approach, Tsinghua Professor Pro code JDK and hotspot source code notes, one-time learning to understand
- C + + recursive knapsack problem
- The use of GIT and GitHub and the latest git tutorial are easy to understand -- Video notes of crazy God speaking
- PostgreSQL statement query
- Ignition database test
- Context didn't understand why he got a high salary?, Nginxfair principle
- Bootstrap switch switch control user's guide, springcloud actual combat video
- A list that contains only strings. What other search methods can be used except sequential search
- [matlab path planning] multi ant colony algorithm grid map path planning [including GUI source code 650]
- [matlab path planning] improved genetic algorithm grid map path planning [including source code phase 525]
- Iinternet network path management system
- Appium settings app is not running after 5000ms
- Reactnative foundation - 07 (background image, status bar, statusbar)
- Reactnative foundation - 04 (custom rpx)
- If you want an embedded database (H2, hsql or Derby), please put it on the classpath
- When using stm32g070 Hal library, if you want to write to flash, you must perform an erase. If you don't let it, you can't write continuously.
- Linux checks where the software is installed and what files are installed
- SQL statement fuzzy query and time interval filtering
- 69. Sqrt (x) (c + + problem solving version with vs runnable source program)
- Fresh students are about to graduate. Do you choose Java development or big data?
- Java project: OA management system (java + SSM + bootstrap + MySQL + JSP)
- Titanic passenger survival prediction
- Vectorization of deep learning formula
- Configuration and use of private image warehouse of microservice architect docker
- Relearn JavaScript events
- For someone, delete return 1 and return 0
- How does Java dynamically obtain what type of data is passed? It is used to judge whether the data is the same, dynamic data type
- How does the database cow optimize SQL?
- [data structure] chain structure of binary tree (pre order traversal) (middle order traversal) (post order traversal) (sequence traversal)
- Webpack packaging optimization solution
- 5. Operation element
- Detailed explanation of red and black trees
- redhat7. 9 install database 19C
- Blue Bridge Cup notes: (the given elements are not repeated) complete arrangement (arrangement cannot be repeated, arrangement can be repeated)
- Detailed explanation of springboot default package scanning mechanism and @ componentscan specified scanning path
- How to solve the run-time exception of test times
- Detailed explanation of k8s management tool kubectl
- Android system view memory command