<template>
<div>
<span>SearchByName: </span>
<input v-model="text"><button type="button" name="button" @click="add">查找</button>
<table border="1" >
<tr>
<th>姓名</th>
<th>性别</th>
<th>年龄</th>
</tr>
<tr v-for = "item in newTableList">
<td>{{item.name}}</td>
<td>{{item.sex}}</td>
<td>{{item.age}}</td>
</tr>
</table>
</div>
</template>
<script>
export default {
data() {
return{
text: '',
msg:"",
tableList:[
{name:"华仔",sex:"男",age:10},
{name:"作别",sex:"女",age:20},
{name:"哈喽",sex:"男",age:30},
{name:"HTML",sex:"女",age:40},
{name:"我爱罗",sex:"男",age:50},
]
}
},
computed: {
newTableList() {
return this.tableList.filter((user)=>{
return user.name.toLowerCase().indexOf(this.msg.toLowerCase()) !== -1;
})
}
},
methods:{
add(){
this.msg = this.text;
}
}
};
</script>
<style media="screen" scoped>
td,th{
padding:10px;
}
table{
text-align: center;
}
</style>
网友评论