<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>
vue2.0自定義過濾器—搜索
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
推薦閱讀更多精彩內(nèi)容
- 關(guān)于$filter的自定義過濾器。要是定義在moduler內(nèi)部使用自定義函數(shù)的方式,那么傳入該函數(shù)的是object...
- 組件模板代碼寫法 多個元素的書寫 問題小結(jié): 組件外面必須有一個根元素包裹(1.0可直接書寫) 組件定義 小結(jié):組...
- 生命周運算期鉤子 所有的生命周期鉤子自動綁定 this 上下文中的實例訪問數(shù)據(jù)對屬性和方法進(jìn)行不能使用es6中的箭...