I have created a simple Vue app that I would like to filter by both the name of a city as well as the code (value). Is this possible?

I know the right way to go is using Vue computed but for some reason I just can't link this one up.


new Vue({
  el: '#app',
  data() {
    return {
      findName: '',
      options: [
  computed: {
    filteredNames() {
      let filter = new RegExp(this.findName, 'i')
      return this.options.filter(el => el.match(filter))

1 Answers

Hazza On Best Solutions

You just need to filter on the properties of your list of options. Check this fiddle: https://jsfiddle.net/zxua4r0m/

The changed code:

return this.options.filter(el => el.text.match(filter) || el.value.match(filter))