@darrion.kuhn
To hide and show divs on button click that are created dynamically in Vue.js, you can follow these steps:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<template> <div> <div v-for="(element, index) in elements" :key="index" :class="{ 'hidden': !element.isVisible }">{{ element.content }}</div> <button @click="toggleDivs">Toggle Divs</button> </div> </template> <script> export default { data() { return { elements: [ { content: 'Div 1', isVisible: true }, { content: 'Div 2', isVisible: true }, { content: 'Div 3', isVisible: true } ] }; }, methods: { toggleDivs() { this.elements.forEach(element => { element.isVisible = !element.isVisible; }); } } }; </script> <style> .hidden { display: none; } </style> |
By following the above steps, you can create a Vue component that dynamically generates and shows/hides divs on button click.