Answer the question
In order to leave comments, you need to log in
How to correctly distribute attributes?
Guys need your help.
I'm trying to make something like a gallery with sorting (result below), but using vue. While I was picking, I finally got confused about attributes v-for="{ ... }"
with inheritance and broke all my code. Help me set it up please...
(below - to give you an idea)
It basically works, for one label:
But in order to work correctly, if I understand correctly, I need to wrap the labels and shapes in separate objects. Made. Actually, the problems started here ...
Result: In the end, it should turn out like this (implementation in css + html):
Answer the question
In order to leave comments, you need to log in
Let's add two properties to the component. Computed is an array of unique values of element types, and normal is an array of user-selected types:
data: () => ({
selectedTypes: [],
...
}),
computed: {
types() {
return [...new Set(this.items.map(n => n.type))];
},
...
},
<template v-for="n in types">
<input type="checkbox" :value="n" v-model="selectedTypes" :id="n">
<label :for="n">{{ n }}</label>
</template>
computed: {
filteredItems() {
const types = this.selectedTypes;
return this.items.filter(n => types.includes(n.type));
},
...
},
<figure v-for="n in filteredItems">
<img :src="n.src" alt="">
</figure>
I did it a little differently, it works, but I used two templates instead of one
https://jsfiddle.net/madeas/s47gqbaz/5/
checked === false
. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question