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
1. Text formatting: This example demonstrates how...
These introduced HTML tags do not necessarily ful...
mapGetters Helper Function mapGetters helper func...
【question】 The INSERT statement is one of the mos...
Table of contents 1. What is the life cycle 2. Lo...
Table of contents text LOCK parameter ALGORITHM p...
1. Create a database: create data data _name; Two...
1. Introduction By enabling the slow query log, M...
MySQL 5.7.20 installation and configuration metho...
Win2008 R2 zip format mysql installation and conf...
MySQL-Group-Replication is a new feature develope...
1. Slow query due to lack of index or invalid ind...
This article records the complete uninstallation ...
1. Two properties of table reset: ①border-collaps...
MySQL consistency log What happens to uncommitted...