表格根据搜索词过滤

在循环绑定的数组上做过滤

   <tr v-for="(item,index) in filterData()" :key="item.id">
            <td>{{item.id}}</td>
            <td>{{item.name}}</td>
            <td>{{item.ctime|timeTrans}}</td>
            <td><a href="#" @click.prevent="deleteData(item.id)">删除</a></td>
   </tr>
            filterData: function () {
                let _this = this;
                return this.list.filter(function (item) {
                    //这里this代表window, _this代表实例
                    // 因为filter方法是window的方法
                    if (item.name.includes(_this.keyword)) {
                        return item;
                    }
                });
            }
发布了39 篇原创文章 · 获赞 2 · 访问量 4030

猜你喜欢

转载自blog.csdn.net/qq_43137725/article/details/103640124