Answer the question
In order to leave comments, you need to log in
How to filter data in a loop?
Good afternoon, there is a store with axios
import Vue from 'vue';
import Vuex from 'vuex';
import axios from 'axios';
Vue.use(Vuex);
export default new Vuex.Store({
namespaced:true,
state: {
ListTicket: '',
},
getters: {
TicketList: state => {
return state.ListTicket.data
},
doneTodos: (state) => (id) => {
let set;
set = state.ListTicket.data;
return set.find(set => set.id === id)
}
},
mutations: {
setList(state, payload){
state.ListTicket = payload;
}
},
actions: {
async getList({commit}){
let response = await axios.get('/account/ticketApi/list');
if (response.status === 200) {
commit('setList', response.data);
}
}
},
modules: {
}
})
return state.ListTicket.data
...mapGetters([
'TicketList',
]),
Answer the question
In order to leave comments, you need to log in
Use a filter for arrays
This filter checks which element of the array contains the key 'available' in the value true:
For id, you can do this:
array.filter(item => item.available)
array.filter((item) => {
return item.id === 42
})
state: {
ListTicket: '',
},
getters: {
TicketList: state => {
return state.ListTicket.data
},
Where did data come from? There just should be return state.ListTicket and
ListTicket: [],
here is what i am trying to do
GetListId: (state) => (id) => {
return state.ListTicket.find(ListTicket => ListTicket.id === id)
}
...mapGetters([
'LIST',
'GetListId'
]),
{{ GetListId(100) }}
"state.ListTicket.find is not a function"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question