简体   繁体   English

Vue.js 2过滤器不适用于数据表

[英]Vue.js 2 filter is not working with data table

Attempting to filter data by the name of the client. 尝试按客户端名称过滤数据。 Tried many options with no luck. 尝试了许多没有运气的选择。 currently i have the list of clients broken out to a separate component with intention to use vuex as the project becomes larger. 目前,我已经将客户列表分解为一个单独的组件,并打算在项目变得更大时使用vuex。 So with that being said i have currently placed the logic for filtering inside my client info component where as the input for the search is in the clients list component. 如此说来,我目前已将用于过滤的逻辑放在我的客户信息组件中,其中搜索的输入在客户列表组件中。 see below 见下文

this is the clients info component 这是客户信息组件

<template>
     <tbody class="client-info">
          <tr v-for="(client, index) in filterClient"  :key="index">
                <td>{{ index }}</td>
                <td>{{ client.name }}</td>
                <td>{{ client.type }}</td>
                <td>{{ client.email }}</td>
                <td>{{ client.phone }}</td>
                <td><router-link v-bind:to="'/client/'+client.id"><i class="far fa-eye"></i></router-link></td>
            </tr>
        </tbody>
</template>

<script>


export default {
    name: 'client-info',
    props: {
        clients: {
            type: Array,
            default: () => []
        }
    },
    data() {
        return {
        search: ''
        }
    },
    created() {
    this.$store.dispatch('retrieveClients')
    },
    computed: { 
     filterClient () {
         return this.clients.filter( client => {
             return !this.searchClient || client.name.toLowerCase().includes(this.searchClient.toLowerCase()) > -1
      })
    }
  }

}
</script>

this is the clients list component 这是客户列表组件

<template>
 <div>


<!-- this is the head of the table list -->
  <table class="table table-bordered table table-light table-striped table-hover">
    <thead class="thead-primary">
      <tr>
          <th scope="col">#</th>
          <th scope="col">Name</th>
          <th scope="col">Type</th>
          <th scope="col">Email</th>
          <th scope="col">Phone</th>
          <th scope="col">Profile</th>
      </tr>
    </thead> 
    <!-- the clients data is imported from client info file -->
    <client-info :clients="allClients"></client-info>      
  </table>



 </div>
</template>

<script>
import { mapGetters } from 'vuex'
import ClientInfo from '@/components/clientslistexperience/ClientInfo'


export default {
name: 'ClientsList',
  components: {
    ClientInfo
  },
  data() {
    return {
      search: null
    }
  },
  computed: {
    ...mapGetters(['allClients']),
  }
}
</script>

i am aware that the data for the search is placed in both components at the moment, just trying different things out. 我知道搜索的数据目前放在两个组件中,只是尝试了不同的方法。 Also that right now it is not being set up to use vuex for the logic and state. 同样,现在还没有设置将vuex用于逻辑和状态。 If I am completely off track please let me know! 如果我完全偏离轨道,请告诉我!

Table tag requires thead , tbody or tr . 表格标签需要theadtbodytr it removes other tag , so put table tag inside your component. 它将删除其他标签,因此将表标签放入组件中。

   <template>
     <div>
         <client-info :clients="allClients"></client-info>
     </div>
  </template>

and put table tag along with all inner tag 并将表格标签和所有内部标签放在一起

   <template>

   <table class="table table-bordered table table-light table-striped table-hover">
  <thead class="thead-primary">
  <tr>
      <th scope="col">#</th>
      <th scope="col">Name</th>
      <th scope="col">Type</th>
      <th scope="col">Email</th>
      <th scope="col">Phone</th>
      <th scope="col">Profile</th>
  </tr>
 </thead> 
 <tbody class="client-info">
 <tr v-for="(client, index) in filterClient"  :key="index">
            <td>{{ index }}</td>
            <td>{{ client.name }}</td>
            <td>{{ client.type }}</td>
            <td>{{ client.email }}</td>
            <td>{{ client.phone }}</td>
            <td><router-link v-bind:to="'/client/'+client.id"><i class="far fa-eye"></i></router-link></td>
        </tr>
    </tbody>
    </template>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM