Home > Article > Web Front-end > Code usage of vue.js+todolist
This time I will bring you the code usage of vue.js todolist. What are the precautions when using the vue.js todolist code. The following is a practical case, let’s take a look.
Case Knowledge Points:
1.vue.js basic knowledge
2.HTML5 local storage localstorage
store.js code
const STORAGE_KEY = 'todos-vue.js' export default{ fetch(){ return JSON.parse(window.localStorage.getItem(STORAGE_KEY) || '[]') }, save(items){ window.localStorage.setItem(STORAGE_KEY,JSON.stringify(items)); } }
App.vue code
<template> <p id="app"> <h1 v-text="title"></h1> <input v-model="newItem" v-on:keyup.enter="addNew"/> <ul> <li v-for="item in items" v-bind:class="{finished:item.isFinished}" v-on:click='toogleFinish(item)'> {{item.label}} </li> </ul> </p> </template> <script> import Store from './store' export default { name: 'app', data () { return { title: 'this is a todo list', items:Store.fetch(), newItem:'' } }, watch:{ items:{ handler(items){ //经过变化的数组会作为第一个参数传入 Store.save(items) console.log(Store.fetch()); }, deep:true //深度复制 } }, methods:{ toogleFinish(item){ item.isFinished = !item.isFinished }, addNew(){ this.items.push({ label:this.newItem, isFinished:false, }) this.newItem = '' } } } </script> <style> #app { font-family: 'Avenir', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } .finished{ text-decoration: underline; } </style>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related matters on the php Chinese website article!
Recommended reading:
Detailed introduction to parameter passing of vue.js parent-child components
Detailed introduction to vue.js divided components
How to implement Ajax with native JS asynchronous requests
The above is the detailed content of Code usage of vue.js+todolist. For more information, please follow other related articles on the PHP Chinese website!