Answer the question
In order to leave comments, you need to log in
How to filter VUEX API data?
Good afternoon!
Can you please tell me how to filter in order the incoming json data (numbers) received via the API from VUEX?
The data itself filters =
{
"age_ratings": [
"16+",
"18+",
"0+",
"12+"
],
...
}
export const state = () => ({
filters: []
})
export const mutations = {
setFilters(state, filters) {
state.filters = filters
}
}
export const actions = {
async filterFilms({ commit }) {
const filters = await this.$axios.$get('apiUrl')
commit('setFilters', filters)
}
}
export const getters = {
filters: st => st.filters
}
< v - select
: items = "filters.age_ratings" //здесь вывожу нужные данные
></v - select >
mounted() {
this.$store.dispatch("films/filterFilms");
},
computed: {
filters() {
return this.$store.getters["films/filters"];
}
}
computed: {
filters() {
return this.$store.getters["films/filters"];
},
ageRatings() {
let age = [];
age.push(this.$store.getters["films/filters"].age_ratings);
//нерабочий велосипед, пробовал отрезать плюс и отсортировать методом sort
age.slice(0, -1).sort(function (a, b) {
return a - b
})
return age
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question