<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<style type="text/css">
#tb {
width: 800px;
border-collapse: collapse;
margin: 20px auto;
}
#tb th {
background-color: #0094ff;
color: white;
font-size: 16px;
padding: 5px;
text-align: center;
border: 1px solid black;
}
#tb tr td {
padding: 5px;
text-align: center;
border: 1px solid black;
}
</style>
<script src="js/vue1026.js"></script>
</head>
<body>
<div id="app">
<input type="text" v-model="id" />
<input type="text" v-model="pname" />
<!--//筛选输入框-->
<input type="text" placeholder="请输入筛选内容" v-model="sname" />
<button @click="addData">添加</button>
<table id="tb">
<tr>
<th>编号</th>
<th>品牌</th>
<th>时间</th>
<th>操作</th>
</tr>
<tr v-show="list.length == 0">
<td colspan="4">当前列表无数据</td>
</tr>
<!--筛选值绑定-->
<tr v-for="item in list | filterBy sname in 'name'">
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.ctime}}</td>
<td>
<a href="javascript:void(0)" @click="delData(item.id)">删除</a>
</td>
</tr>
</table>
</div>
</body>
<script>
new Vue({
el: '#app',
data: {
list: [{
id: 1,
name: '奔驰',
ctime: new Date
}],
id: 0,
pname: '',
sname: '' /*筛选值定义*/
},
methods: {
addData: function() {
var p = {
id: this.id,
name: this.pname,
ctime: new Date()
};
this.list.push(p);
this.id = 0;
this.pname = '';
},
delData: function(id) {
if(!confirm('是否要删除数据')) {
return;
}
var index = this.list.findIndex(function(item) {
return item.id == id
})
this.list.splice(index, 1)
}
}
});
</script>
</html>
本文属于学习笔记