How to call the attributes in computed in vue2.x filters. In addition, the method in filters adds multiple parameters, and the call in template reports an error.

the following is demo

<script>
  export default {
    props: ["userList", "sessionIndex", "session", "search"],
    filters: {
      selection (list, sear) {
        return list.filter(item => item.name.indexOf(sear) > -1)
      }
    }
  }
</script>

<template>
    <div class="m-list">
        <ul>
            <li v-for="item in userList | selection(search)" :class="{ active: session.userId === item.id }">
                <img class="avatar" width="30" height="30" :alt="item.name" :src="item.img">
                <p class="name">{{item.name}}

</li> </ul> </div> </template>

console error message is as follows

Vue warn: Property or method "selection" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

Error in render: "TypeError: _vm.selection is not a function"

TypeError: _vm.selection is not a function

filter will not bind this. If you cannot get an instance, you can only do simple processing. You need to write another computed for filtering, and the interface can bind the filtered data directly.

Menu