<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<input type="text" v-model="val" @keyup.13="add">
<ul>
<li v-for="(item,index) in arr">{{item}} <button @click="del(index)">删除</button></li>
</ul>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
let vm = new Vue({
el:"#app",
data:{
arr:[],
val:''
},
methods:{
add(){
this.arr.unshift(this.val);
this.val='';
},
del(index){
this.arr = this.arr.filter(function (item,i) {
if(i===index){
return false;
}
return true;
})
}
}
})
</script>
</html>
Vue实现todolist
最新推荐文章于 2024-03-17 11:40:46 发布