<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>note</title>
</head>
<body>
<div id="app">
<input type="text" @keyup.enter="add" v-model="addEvent">
<ul>
<li v-for="(event,index) in note" @mouseenter="enter(index)" @mouseleave="leave(index)">
{{index+1}}. {{event}}
<span @click="remove(index)" v-show="ishow && index == current"> X </span>
</li>
</ul>
<hr>
<span v-text="'一共有 ' + note.length + ' 件事情还没干呢'" v-if="note.length != 0"></span>
<br>
<br>
<span @click="clear" v-if="note.length != 0">老子不干了</span>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
note: ['吃饭饭', '睡觉觉', '打豆豆'],
addEvent: '',
ishow: false,
current: 0
},
methods: {
clear: function () {
this.note = [];
},
add: function () {
this.note.push(this.addEvent)
},
remove: function (index) {
this.note.splice(index, 1)
},
enter(index) {
this.ishow = true;
this.current = index;
},
leave(index) {
this.ishow = false;
this.current = null;
}
}
})
</script>
</body>
</html>