Answer the question
In order to leave comments, you need to log in
How to hide one component and show another in vuejs if they are the same?
Hello.
I have several identical components on the page:
<div>
<button @click="showPicker = !showPicker">Button 1</button> // По нажатию на эту кнопку должен открыться
<sketch-picker v-model="h1Color" v-if="showPicker" /> // этот компонент
</div>
<div>
<button @click="showPicker = !showPicker">Button 2</button> // А по нажатию на эту кнопку должен открыться
<sketch-picker v-model="h2Color" v-if="showPicker" /> // этот компонент
</div>
// но по нажатию на любую из кнопок открываются оба компонента и так же закрываются.
<script>
new Vue({
el: '#app',
components: {
'sketch-picker': sketch,
},
data() {
return {
showPicker: false,
h1Color: '#555555',
h2Color: '#555555',
}
}
});
</script>
Answer the question
In order to leave comments, you need to log in
The simplest thing is to make a showPicker property for each,
that is, showPicker1 changes on the first button and displays 1
showPicker2 element - similarly with the second
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question