最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

vue.jstodolist如何实现

来源:动视网 责编:小采 时间:2020-11-27 20:08:06
文档

vue.jstodolist如何实现

vue.jstodolist如何实现:这次给大家带来的是vue.js todolist如何实现,首先我们要知道vue.js基础知识和HTML5 本地存储localstorage,这篇文章就给大家好好分析一下。store.js代码const STORAGE_KEY = 'todos-vue.js' export default{ fe
推荐度:
导读vue.jstodolist如何实现:这次给大家带来的是vue.js todolist如何实现,首先我们要知道vue.js基础知识和HTML5 本地存储localstorage,这篇文章就给大家好好分析一下。store.js代码const STORAGE_KEY = 'todos-vue.js' export default{ fe


这次给大家带来的是vue.js todolist如何实现,首先我们要知道vue.js基础知识和HTML5 本地存储localstorage,这篇文章就给大家好好分析一下。

store.js代码

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代码

<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>

相信看了以上介绍你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!

相关阅读:

ES6解构赋值的功能如何使用

js实现仿window系统日历效果

JS怎样可以做到点击跳转到登陆的个人邮箱

文档

vue.jstodolist如何实现

vue.jstodolist如何实现:这次给大家带来的是vue.js todolist如何实现,首先我们要知道vue.js基础知识和HTML5 本地存储localstorage,这篇文章就给大家好好分析一下。store.js代码const STORAGE_KEY = 'todos-vue.js' export default{ fe
推荐度:
标签: VUE 实现 js
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top