<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My todo list</title>
<style>
*{
list-style: none;
outline: none;
border: none;
box-sizing: border-box;
margin: 0;
padding: 0;
}
.app h1,.app p{
text-align: center;
margin-top: 10px;
}
#app{
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #2C3E7A;
}
.app{
width: 640px;
margin: 0 auto;
background: #c5c5c5;
padding:30px 10px;
border: 1px solid #2C3E7A;
margin-top: 10px;
position: relative;
box-shadow: 0 0 10px #2C3E7A;
}
.app:before{
content: '';
width: 2px;
border-left: 1px dashed #2C3E7A;
border-right: 1px dashed #2C3E7A;
height: 100%;
position: absolute;
top: 0;
left: 51px;
}
.app li{
cursor: pointer;
height: 45px;
line-height: 45px;
padding-left: 65px;
position: relative;
border-bottom: 1px dashed #2C3E7A;
}
.todo-box li input{
text-align: center;
width: 40px;
height: auto;
position: absolute;
top: 0;
bottom: 0;
left: 0;
margin:0 auto;
border: none;
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
-o-appearance: none;
appearance: none;
}
.todo-box li input:after{
content: '?';
line-height: 43px;
font-size: 20px;
color: #f0f0f0;
text-shadow: 0 -1px 0 #bfbfbf;
}
.app li.finished{
text-decoration: line-through;
color: #4fc08d;
}
.app li.finished input:after{
color: #4fc08d;
text-shadow: 0 1px 0 #669991;
bottom: 1px;
position: relative;
}
.typeInput input{
width: 81%;
color: #2C3E7A;
font-size: 24px;
border: 1px solid #2C3E7A;
padding: 1%;
transition: all 0.3s ease-in-out;
}
.typeInput input:focus {
outline: none;
border-color: #2C3E7A;
box-shadow: 0 0 10px #2C3E7A;
}
</style>
</head>
<body>
<div id="app" class="app">
<h1 v-text='title'></h1>
<p class='typeInput'>
<input type="text" v-model='newText' v-on:keyup.enter='addNewlist'>
</p>
<ul class="todo-box">
<li v-for='item in items' v-bind:class='{finished:item.isFinished}'>
<input type="checkbox" v-on:click='toggleFinish(item)'>
{{item.text}}
</li>
</ul>
</div>
<script type="text/javascript" src="http://cn.vuejs.org/js/vue.js"></script>
<script type="text/javascript">
const STORAGE_KEY = 'todos-vuejs';
const Store = {
fetch() {
return JSON.parse(window.localStorage.getItem(STORAGE_KEY)||'[]');
},
save( items ) {
window.localStorage.setItem(STORAGE_KEY,JSON.stringify(items));
}
};
const app = new Vue({
el: '#app',
data: {
title: 'My todo list',
// items:[
// // {
// // text:'Learn CSS',
// // isFinished:true
// // },
// // {
// // text:'Learn javascript',
// // isFinished:false
// // }
// ],
items: Store.fetch(),
newText: ''
},
//watch深度監(jiān)聽函數(shù),監(jiān)聽的是items的變化
//只要有新的輸入內(nèi)容就會觸發(fā)耿导,
watch: {
items: {
//val和oldval這里都是對象
handler(items) {
// console.log(items);
Store.save( items );
},
deep:true
}
},
//
methods:{
toggleFinish(item) {
// console.log(item.isFinished);
item.isFinished=!item.isFinished;
},
//3便脊、輸入后按enter鍵盤的事件
addNewlist() {
let _self = this;
//3.1 如果不為空就將剛剛輸入的內(nèi)容以對象的形式产场,追加到items數(shù)組對象內(nèi)部隔节,
//默認新追加的是沒完成的為false
if( _self.newText ) {
_self.items.push({
text: _self.newText,
isFinished: false
});
}
// console.log(_self.newText);
// console.log(this);
//3.2 同時清空input輸入框
_self.newText = '';
}
}
});
</script>
</body>
</html>
vue.js - todolist
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來豆茫,“玉大人侨歉,你說我怎么就攤上這事】辏” “怎么了为肮?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長肤京。 經(jīng)常有香客問我颊艳,道長茅特,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任棋枕,我火速辦了婚禮白修,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘重斑。我一直安慰自己兵睛,他們只是感情好,可當我...
- 文/花漫 我一把揭開白布窥浪。 她就那樣靜靜地躺著祖很,像睡著了一般。 火紅的嫁衣襯著肌膚如雪漾脂。 梳的紋絲不亂的頭發(fā)上假颇,一...
- 文/蒼蘭香墨 我猛地睜開眼辙浑,長吁一口氣:“原來是場噩夢啊……” “哼激涤!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起判呕,我...
- 正文 年R本政府宣布肥矢,位于F島的核電站端衰,受9級特大地震影響叠洗,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜旅东,卻給世界環(huán)境...
- 文/蒙蒙 一灭抑、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧抵代,春花似錦腾节、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至康吵,卻和暖如春劈榨,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背涎才。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 3.單選按鈕 選擇一個網(wǎng)站 51code Google 選擇的網(wǎng)站是: {{selected}} new Vue(...
- 前言 本文將會介紹 MVVM 和 Vue.js 的相關(guān)話題. 由于本人寫了一些關(guān)于 Vue.js 封裝的文章, 并...
- 目前理解來說茎芋,不管哪種js他們的本質(zhì)都是颅眶,javaScript。而這些到都是經(jīng)過包裝編寫田弥,編寫變成另外一種規(guī)則涛酗。更...
- 一:MVVM框架 MVVM框架的應(yīng)用場景: 1商叹、針對具有復(fù)雜交互邏輯的前端應(yīng)用2、提供基礎(chǔ)的架構(gòu)抽象3只泼、提供aj...
- 三大問之第一問-是什么Vue.js是一套構(gòu)建用戶界面的漸進式框架请唱。和大家耳熟能詳?shù)钠渌岸丝蚣芤粯用诌洌捎糜谇岸水a(chǎn)品...