美文网首页
vue2.0自定义过滤器—搜索

vue2.0自定义过滤器—搜索

作者: 前端小华子 | 来源:发表于2017-09-15 17:37 被阅读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>
    

    相关文章

      网友评论

          本文标题:vue2.0自定义过滤器—搜索

          本文链接:https://www.haomeiwen.com/subject/kncesxtx.html