This article mainly introduces the case of Vue encapsulating a TodoList and the application implementation of browser local cache, and shares it with you, as follows:
Browser local cache:
It can be seen that their prototype chains are basically the same, the only difference is that
In this example, sessionStorage is used and a small package is made for it. const storage = { set(key, value){ window.sessionStorage.setItem(key, JSON.stringify(value)); }, get(key){ return JSON.parse(window.sessionStorage.getItem(key)); }, remove(key){ window.sessionStorage.removeItem(key); } } export default storage; Example code:<template> <div class="todo"> <header> <input type="text" placeholder="Enter..." v-model="keyword" @keydown.enter="handleList"> TodoList </header> <!-- In Progress --> <h4>In progress...{{dolistNumber}}</h4> <template v-for="(item, index) in dolist" :key="index"> <div class="dolist" v-if="!item.checked"> <label :for="index +'l'"> <input type="checkbox" v-model="item.checked" :id="index +'l'" @change="handleChecked"> {{item.title}} </label> <span @click="cancalDo(index)">X</span> </div> </template> <!-- Completed --> <h4>Completed...{{dolist.length - dolistNumber}}</h4> <template v-for="(item, index) in dolist" :key="index"> <div class="dolist" v-if="item.checked"> <label :for="index +'ll'"> <input type="checkbox" v-model="item.checked" :id="index +'ll'" @change="handleChecked"> {{item.title}} </label> <span @click="cancalDo(index)">X</span> </div> </template> </div> </template> <script> import storage from '../storage.js'; export default { name: "todoList", data() { return { keyword: "", // input options dolist: [], } }, computed:{ dolistNumber(){ return this.dolist.filter(item => item.checked === false).length; } }, methods: { handleChecked(){ // Refresh after changing the status storage.set('dolist', this.dolist); }, handleList() { if (this.keyword !== "") { this.dolist.push({ title: this.keyword, checked: false, }); this.keyword = ""; storage.set('dolist', this.dolist); } }, cancalDo(index) { // delete this this.dolist.splice(index, 1); storage.set('dolist', this.dolist); } }, mounted(){ let dolist = storage.get('dolist'); if(dolist){ this.dolist = dolist; } }, } </script> <style> .todo { margin: 400px auto; min-height: 300px; width: 800px; background-color: #eee; } .todo header { position: relative; text-align: center; height: 60px; line-height: 60px; font-size: 20px; border-bottom: 2px solid #fff; } .todo header input { position: absolute; left: 40px; top: 50%; transform: translateY(-50%); outline: none; line-height: 30px; border-radius: 15px; padding-left: 30px; border: 1px solid #999; font-size: 16px; width: 100px; transition: all .6s linear; } .todo header input:focus { width: 200px; } .dolist { padding: 20px; font-size: 16px; } .dolist label { cursor: pointer; } .dolist input { margin-right: 10px; } .dolist span:last-child { float: right; border: 1px solid gray; background-color: #999; color: #fff; border-radius: 50%; padding: 5px; } h4 { padding-bottom: 20px; text-align: center; } </style> This concludes this article about the case of Vue encapsulating a TodoList and the application implementation of browser local cache. For more relevant Vue TodoList content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of using top command to analyze Linux system performance
>>: Brief analysis of the MySQL character set causing database recovery errors
If you want to transfer files between Windows and...
Table of contents Drop-down multiple-select box U...
Error: Connection to blog0@localhost failed. [080...
<br />Sometimes you may be asked questions l...
Table of contents 1. Shallow cloning 2. Deep clon...
Table of contents 1. Ternary operator judgment 2....
How Nginx works Nginx consists of a core and modu...
nginx is our most commonly used server, often use...
When processing batch updates of certain data, if...
In the past few years of my career, I have writte...
Table of contents Written in front Environment de...
Table of contents Preface 1. Recursive components...
Xiaobai records the installation of vmtools: 1. S...
A jQuery plugin every day - jQuery plugin to impl...
This tag is not part of HTML3.2 and is only suppo...