filter模糊查询

64 阅读1分钟
<template>
  <div id="app">
    <input oninput="search" type="text" v-model="input" />
    <ul>
      <li
        class="search-item border-bottom"
        v-for="item of search"
        :key="item.name"
      >{{item.name}}</li>
    </ul>
    <!-- <router-view></router-view> -->
  </div>
</template>

<script>
export default {
  name: "app",
  data() {
    return {
      items: [
        { name: "路飞" },
        { name: "索隆" },
        { name: "娜美" },
        { name: "山治" }
      ],
      input: "",
      itemsTwo:[]
    };
  },
  mounted: {
    search() {
    this.itemsTwo=this.items
      if (!this.input) {
        this.items=this.itemsTwo
        return 
      }
      let arr=this.items.filter(v => {
        return v.name.includes(this.input);
      });
      this.items=arr
    }
  }
};
</script>