vue列表条件模糊搜索

后端返回数组

list: [{labourEnterpriseName: '猪八戒', },{labourEnterpriseName: '1231'},
    {labourEnterpriseName: '猪1231', },{labourEnterpriseName: '1212323'},
    {labourEnterpriseName: '1222103', },{labourEnterpriseName: '1231'},
    {labourEnterpriseName: '最新数据', },{labourEnterpriseName: '测试'},
    {labourEnterpriseName: '测试2', },{labourEnterpriseName: '金元宝逃离'}, ]

完整代码(利用计算树形进行筛选)

 <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8" />
        <title>模糊搜索</title>
        <script src="./vue.js"></script>
        <style type="text/css">
          body {
            background-color: #cecece;
          }
          input {
            height: 25px;
            margin-bottom: 10px;
          }
        </style>
      </head>
      <body>
        <div id="app">
          <h1>名字筛选</h1>
          <el-input
            placeholder="输入关键字进行过滤"
            v-model="keyword"
          ></el-input>
          <div class="list">
            <div
              class="corporation"
              v-for="(item, index) in flist"
              :key="index"
              :class="{ 'corporation-active': item.id === corporationId }"
              @click="changeCo(item)"
            >
              {{ item.labourEnterpriseName }}
            </div>
          </div>
        </div>
        <script type="text/javascript">
          new Vue({
            el: "#app",
            data: {
              keyword: "",
              list: [
                { labourEnterpriseName: "猪八戒" },
                { labourEnterpriseName: "1231" },
                { labourEnterpriseName: "猪1231" },
                { labourEnterpriseName: "1212323" },
                { labourEnterpriseName: "1222103" },
                { labourEnterpriseName: "1231" },
                { labourEnterpriseName: "最新数据" },
                { labourEnterpriseName: "测试" },
                { labourEnterpriseName: "测试2" },
                { labourEnterpriseName: "金元宝逃离" },
              ],
            },
            computed: {
              flist() {
                // 如果输入的名字在list存在,返回有这个字的名字
                // item.name这里是按名字搜索,也可按其他进行搜索
                return this.list.filter((item) =>
                  item.labourEnterpriseName.includes(this.keyword)
                );
              },
            },
          });
        </script>
      </body>
    </html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值