vue2.0自定義過濾器—搜索

<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>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容