A
A
Andrej Sharapov2020-03-03 09:32:35
Vue.js
Andrej Sharapov, 2020-03-03 09:32:35

How to setup v-switch filter for json?

1. there is a switch <v-switch v-model="filtered">
2. there is a json array with objects that contain the following structure:

list: [
        {
          ...,
          ...,
          stateId: 1
          ...,
        },
        {
          ...,
          ...,
          stateId: 0
          ...,
        },
        {
          ...,
          ...,
          stateId: 0
          ...,
        },
        {
          ...,
          ...,
          stateId: 1
          ...,
        }
      ]


Tell me how to set up a filter so that it shows and hides all cards with the status "0"?
,
  computed: {
    stateId() {
      return this.list.stateId;
    }
  },
  methods: {
    filtered() {
      return //- как настроить фильтр?
    }
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-03-03
@Madeas

Create a computed property that, based on some switch, returns either the full array or the filtered array. And in template use this property instead of list

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question