<!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>Documen</title>
</head>
<body>
<!-- 主体区域 -->
<div id="app">
<!-- 输入框 -->
<header class="header">
<h1>记事本</h1>
<!-- 设定输入回车时提交 触发函数 -->
<input placeholder="请输入任务" v-model="inputValue" @keyup.enter="add">
</header>
<section>
<ul>
<li v-for="(item,index) in list">
<span>{{index+1}}</span>
<label>{{item}}</label>
<button @click="remove(index)">删除</button>
</li>
</ul>
</section>
<footer>
<span><strong v-text="list.length+‘ ‘"></strong>item left</span>
</footer>
</div>
<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
var app = new Vue({
el: ‘#app‘,
data: {
list:["玩游戏","敲代码"],
inputValue:""
},
methods:{
add:function(){
this.list.push(this.inputValue)
},
remove:function(index){
this.list.splice(index,1);
},
}
})
</script>
</body>
</html>
Vue简单项目 记事本