localstorage和vue结合使用2

html
<template>
<div class="hello">
<div class="page-top">
<div class="page-content">
<h2>任务计划列表</h2>
</div>
</div>
<div class="main">
<h3 class="big-title">添加任务:</h3>
<input
placeholder="例如:吃饭睡觉打豆豆; 提示:+回车即可添加任务"
class="task-input"
type="text"
v-model="todo"
v-on:keyup.enter="addTodo"
/>
<ul class="task-count" >
<li >0个任务未完成</li>
<li class="action">
<a class="active" href="#all">所有任务</a>
<a href="#unfinished">未完成的任务</a>
<a href="#finished">完成的任务</a>
</li>
</ul>
<h3 class="big-title">任务列表:</h3>
<div class="tasks">
<span class="no-task-tip" v-show="!list.length">还没有添加任何任务</span>
<ul class="todo-list">
<li class="todo" :class="{completed:item.isChecked,editing:item===edtorTodos}" v-for="item in list">
<div class="view">
<input class="toggle" type="checkbox" v-model="item.isChecked"/>
<label @dblclick="edtorTodo(item)">{{item.title}}</label>
<button class="destroy" @click="deleteTodo(item)"></button>
</div>
<input
v-foucs="edtorTodos === item"
class="edit"
type="text"
v-model = "item.title"
@keyup.enter="edtorTodoed(item)"
@keyup.esc="cancelTodo(item)"
@blur="edtorTodoed(item)"
/>
</li>
</ul>
</div> </div>
</div>
</template>
js
我在main.js里面引入了一个自定义的storage.js库
库
/*
storage 主要放项目中的storage相关操作:存取等
*/
var storage = {
/**
对本地数据进行操作的相关方法,如localStorage,sessionStorage的封装
*/
setStorage: function(key, value, duration) {
var data = {
value: value,
expiryTime: !duration || isNaN(duration) ? 0 : this.getCurrentTimeStamp() + parseInt(duration)
};
localStorage[key] = JSON.stringify(data);
},
getStorage: function(key) {
var data = localStorage[key];
if (!data || data === "null") {
return null;
}
var now = this.getCurrentTimeStamp();
var obj;
try {
obj = JSON.parse(data);
} catch (e) {
return null;
}
if (obj.expiryTime === 0 || obj.expiryTime > now) {
return obj.value;
}
return null;
},
removeStorage: function(key){
localStorage.removeItem(key);
},
getSession: function(key) {
var data = sessionStorage[key];
if (!data || data === "null") {
return null;
}
return JSON.parse(data).value; },
setSession: function(key, value) {
var data = {
value: value
}
sessionStorage[key] = JSON.stringify(data);
},
getCurrentTimeStamp: function() {
return Date.parse(new Date());
}
};
export default storage;
import storage from '@/utils/storage.js'
Vue.config.productionTip = false
//将常用工具方法扩展成Vue实例
Vue.prototype.$storage=storage;
export default {
components:{Tab2},
data () {
return {
todo:"",
list:[],
beforeTitle:"",
edtorTodos:""
}
},
created(){
if(this.$storage.getStorage("miao-class")){
var index=this.$storage.getStorage("miao-class");
this.list=index;
}
},
watch:{
list:{
handler:function(val,oldVal){
this.$storage.setStorage("miao-class",val);
},
deep:true
}
},
computed:{
},
methods: {
addTodo(){
this.list.push({
title:this.todo,
isChecked:false
})
this.todo='';
},
deleteTodo(todo){
var index=this.list.indexOf(todo);
this.list.splice(index,1);
},
edtorTodo(todo){
this.beforeTitle=todo.title,
this.edtorTodos=todo;
},
edtorTodoed(todo){
//编辑成功
this.edtorTodos='';
},
cancelTodo(todo){
//取消编辑
todo.title=this.beforeTitle;
this.beforeTitle = '';
//让div显示出来,input隐藏
this.edtorTodos = '';
}
},
directives:{
"foucs":{
update(el,binding){
if(binding.value){
el.focus();
}
}
}
}
}
</script>
localstorage和vue结合使用2的更多相关文章
- localstorage和vue结合使用
父组件 <template> <div class="hello"> <p>Original message:"{{message}} ...
- vue中使用localStorage存储信息
一 什么是localStorage 对浏览器来说,使用 Web Storage 存储键值对比存储 Cookie 方式更直观,而且容量更大,它包含两种:localStorage 和 sessionSto ...
- Vue应用框架整合与实战--Vue技术生态圈篇
实用框架以及工具 UI组件 开发框架 实用库 服务端 辅助工具 应用实例 Demo示例 UI组件 Element-UI ★13489 - 饿了么出品的Vue2的web UI工具套件 Vux ★8133 ...
- 【转载】 github vue 高星项目
内容 UI组件 开发框架 实用库 服务端 辅助工具 应用实例 Demo示例 UI组件 element ★13489 - 饿了么出品的Vue2的web UI工具套件 Vux ★8133 - 基于Vue和 ...
- VUE组件汇总
内容 UI组件 开发框架 实用库 服务端 辅助工具 应用实例 Demo示例 UI组件 element ★13489 - 饿了么出品的Vue2的web UI工具套件 Vux ★8133 - 基于Vue和 ...
- 【分享】Vue 资源典藏(UI组件、开发框架、服务端、辅助工具、应用实例、Demo示例)
Vue 资源典藏,包括:UI组件 开发框架 服务端 辅助工具 应用实例 Demo示例 element ★11612 - 饿了么出品的Vue2的web UI工具套件 Vux ★7503 - 基于Vue和 ...
- Vue开源项目汇总(史上最全)(转)
目录 UI组件 开发框架 实用库 服务端 辅助工具 应用实例 Demo示例 UI组件 element ★13489 - 饿了么出品的Vue2的web UI工具套件 Vux ★8133 - 基于Vue和 ...
- vue(6)生态
来自:https://www.jianshu.com/p/22a99426b524?utm_campaign=maleskine&utm_content=note&utm_medium ...
- Vue相关开源项目库汇总 http://www.opendigg.com/tags/front-vue
awesome-github-vue 是由OpenDigg整理并维护的Vue相关开源项目库集合.我们会定期同步OpenDigg上的项目到这里,也欢迎各位提交项目给我们. 如果收录的项目有错误,可以通过 ...
随机推荐
- sql server连接字符串与tcp/ip开启
连接字符串1:Data Source=localhost,1433;User ID=sa;Password=123;Initial Catalog=test;Min Pool Size=1;Max P ...
- swift重写导航控制器类的 initialize 方法
//这个方法,是当这个类第一次被创建时调用,且只调用一次 override class func initialize() { let navBar = UINavigationBar.appeara ...
- UITableView性能的优化()
1.0 使用不透明视图 不透明的视图可以极大地提高渲染的速度. 2.0 不要重复创建不必要的cell 也就是我们常说的 循环利用机制 (建立缓冲池) 3.0 减少视图的数目 4.0 不要做多余的绘 ...
- for嵌套
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- yyyy-MM-dd 转换为年月日
yyyy-MM-dd 转换为年月日 先用parse转成date型,再用format转成string. Date date = new SimpleDateFormat("yyyy-M ...
- WINDOW 2008多人访问设置
gpedit.msc,在组策略中对位于“计算机配置->策略->管理模板->Windows 组件->远程桌面服务->远程桌面会话主机->连接”中,限制连接数量中进行配 ...
- ssh 使用 aws
使用 PuTTY 从 Windows 连接到 Linux 实例 启动您的实例之后,您可以连接到该实例,然后像使用您面前的计算机一样来使用它. 注意 启动实例后,需要几分钟准备好实例,以便您能连接到实例 ...
- Fiddler抓包域名过滤(转载)
转载自 http://www.cnblogs.com/111testing/p/6440480.html Fiddler抓包域名过滤 我们在用Fiddler抓包的时候会抓到很多不需要的数据包,我们怎样 ...
- 手机通过Charles抓取https包
因为fiddler不能在mac上使用,而Charles是跨平台的,可以在mac上使用,所以需要了解一下Charles的使用 安装破解版Charles 下载破解版包,先启动一次未破解版的Ch ...
- 对象转化为json
google开发的Gson转换利器,String json = new Gson ().toJson(object); 一行代搞定. 别忘了引入jar包 转自:https://zhidao.baidu ...