vue todolist
2018-06-24 02:14:38来源:未知 阅读 ()
最近初学vue,做最简单的todolist
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>todolist</title>
<style type="text/css">
#container{
width: 700px;
height: 100px;
padding: 40px;
margin: 0 auto;
}
li{
list-style: none;
}
.close-btn{
display: inline-block;
width: 20px;
height: 20px;
background: url('close.png') no-repeat;
cursor: pointer;
}
.finished{
text-decoration: line-through;
}
</style>
</head>
<body>
<div id="container">
<input type="text" v-model="newitem" @keyup.enter="addlistitem"/>
<div class="todo-list">
<ul>
<li v-for="(listitem,index) in list">
<input type="checkbox" v-model="listitem.isFinished" />
<span v-bind:class="{ finished: listitem.isFinished }" >{{ listitem.text }}</span>
<span class="close-btn" @click="deleteitem(index)"></span>
</li>
</ul>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
var app = new Vue({
el: '#container',
data: {
newitem:'',
list:[]
},
watch: {
// 如果 `list`数据 发生改变,这个函数就会运行
list: {
handler:function () {
this.saveTolocal(this.list)
},
// 深度观察,当对象里的属性发生改变时,也会触发watch。点击checkbox需要deep: true,否则watch不会起作用。
deep: true
}
},
methods:{
// 添加项目
addlistitem:function(){
if(this.newitem != ''){
this.list.push({'text':this.newitem,'isFinished':false})
this.newitem = ''
}
},
// 删除项目
deleteitem:function(curIndex){
this.list.splice(curIndex,1)
},
// 存入localStorage
saveTolocal:function(data){
localStorage.setItem('tododata',JSON.stringify(data))
}
}
});
// 读取localStorage
if(!!localStorage.getItem('tododata')){
app.list = JSON.parse(localStorage.getItem('tododata'))
}
</script>
</body>
</html>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:浮动介绍和定位注意点
下一篇:CSS的常用属性(三)
- 循序渐进VUE+Element 前端应用开发(5)--- 表格列表页面的查 2020-07-15
- 循序渐进VUE+Element 前端应用开发(5)--- 表格列表页面的查 2020-07-15
- 循序渐进VUE+Element 前端应用开发(5)--- 表格列表页面的查 2020-07-14
- 循序渐进VUE+Element 前端应用开发(5)--- 表格列表页面的查 2020-07-13
- 循序渐进VUE+Element 前端应用开发(5)--- 表格列表页面的查 2020-07-02
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
