我试图通过在单击事件上更改 filterKey 来更改过滤器,这可能吗?或者有没有更好的方法来实现这一目标?
<a href="#" v-on:click="filterKey = 'all'">All</a>
<a href="#" v-on:click="filterKey = 'nearby'">Nearby</a>
<ul v-for="user in users | filterBy filterKey">
<li>{{user.name}}</li>
</ul>
data () {
return {
filterKey: 'all',
users: users,
}
},
filters: {
all: (users) => {
return users
},
nearby: (users) => {
return users.filter((users) => {
return users.distance <= 15
})
}
}
Run Code Online (Sandbox Code Playgroud) vue.js ×1