how to make items true in an object when user clicked on button vuejs?

Viewed 87

I have an object, and also I have a button, I gonna add an event listener over the button with @click which when the user clicked on the button, those three items be true

here my codes:

<template>
    <div>
        <button @click="isVisible">Click</button>
    </div>
</template>
<script>
export default {
  data() {
    return {
      isVisibleItems: {
        isVisibleOne: false,
        isVisibleTwo: false,
        isVisibleThree: false,
      },
    };
  },
  methods:{
      isVisible(){
        //   what should i put here?
      }
  }
};
</script>
1 Answers

You could loop over the isVisibleItems object keys and set their values to true :

 methods:{
      isVisible(){
          Object.keys(this.isVisibleItems).forEach(key=>{
             this.isVisibleItems[key]=true 
           }
      }
 }
Related