Answer the question
In order to leave comments, you need to log in
How to show only one component that is used multiple times?
There is a component <comment>
, and in it <reply-form>
. Of course, there are a lot of comments on one page and initially they are all <reply-form>
hidden, and if you click on the button under the comment, a response form will open. So, if you click under each comment, then in the end all the forms will be visible. How to make it so that if one component <reply-form>
is visible, then the others would be hidden?
Answer the question
In order to leave comments, you need to log in
Is the parent always shared? If so, then add a property to it that will indicate in which of your component instances you want to display additional elements. As a value, you can use the index of the instance, for example (it is not necessary, some property from the objects with data, on the basis of which the component instances are created, is also suitable - the main thing is that the values \u200b\u200bare unique, of the id type):
data: () => ({
items: [ ... ],
active: null,
}),
<v-xxx
v-for="(n, i) in items"
:показыватьДополнительныйКонтент="active === i"
@переключитьОтображениеДополнительногоКонтента="active = active === i ? null : i"
...
const xxx = Vue.observable({ active: null });
computed: {
показыватьДополнительныйКонтент() {
return xxx.active === this.какоеТоСвойствоСУникальнымЗначением;
},
},
<div v-if="показыватьДополнительныйКонтент">
...
</div>
methods: {
переключитьОтображениеДополнительногоКонтента() {
xxx.active = this.показыватьДополнительныйКонтент
? null
: this.какоеТоСвойствоСУникальнымЗначением;
},
},
<button @click="переключитьОтображениеДополнительногоКонтента">
{{ показыватьДополнительныйКонтент ? 'hide' : 'show' }}
</button>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question