Search
 
SCRIPT & CODE EXAMPLE
 

HTML

vuejs toggle on each in v-for

<template>
  <ul>
    <li v-for="item in items" :class="{ activeclass: item.isActive }">
      <div class="item-text">
        {{ item.text }}
      </div>
      <button @click="toggle(item)">show</button>
      <div v-show="item.isActive" class="item-desc">
        {{ item.desc }}
      </div>
    </li>
  </ul>
</template>

<script>
  export default {
    data () {
      return {
        items: [
          {
            isActive: false,
            text: 'Foo',
            desc: 'The Array.from() method creates a new Array instance from an array-like or iterable object.',
          },
          {
            isActive: false,
            text: 'Bar',
            desc: 'The Array.from() method creates a new Array instance from an array-like or iterable object.',
          }
        ],
      }
    },
    methods: {
      toggle(item, items) {
        items.forEach((el) => {
          if (el === item) {
            el.isActive = !el.isActive;
          } else {
            el.isActive = false;
          }
        })
      }
    },
  }
</script>
Comment

PREVIOUS NEXT
Code Example
Html :: copy to cllipboard the html element 
Html :: node js barcode generator 
Html :: html stroke width not working 
Html :: HTML - The Head Element 
Html :: how to add an email box in html 
Html :: metabase 
Html :: js coding practices airbnb 
Html :: html relative path go back one directory 
Html :: html table resize columns 
Html :: bootstrap links 
Html :: como limpar as informações de uma tabela html 
Html :: dynamic html table python 
Html :: input text before element 
Html :: pattern input html 
Html :: html image styling 
Html :: rounded scrolling images 
Html :: get all html element data using angular 
Html :: html add line break in string on screen size 
Html :: input radio button html 
Html :: html5 time input 24 hour format 
Html :: metal gear 
Html :: negrit html 
Html :: split input for otp 
Html :: balise li forme valider 
Html :: django html 3.2.4 background image not working 
Html :: lorem long text 
Html :: 11ty do not output writing file to terminal 
Html :: http://www.w3.org/1999/xhtml 
Html :: html,css,javascript top 50 quetions 
Html :: py-script run external program 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =