1
<template>
 <div v-for="(item ,index) in items" v-if="showing">
                <span @click="showing=false">{{item.name}}</span>
 </div>
</template>
    <script>

            export default{
                       showing:true,
                       items: [
                          {'name':'a'},
                          {'name':'b'},
                          {'name':'c'},
                       ],
            }
    </script>

how to hide specific div when i click div ** when i do this way it`s all of them was hide**

3 Answers 3

4

I will do something like this:

<template>
   <div v-for="(item,index) in items" v-if="hide.indexOf(index) < 0">
     <span @click="hide.push(index)">{{item.name}}</span>
   </div>
</template>  
<script>
  export default{
    hide :[],
    items:[
     {'name':'a'},
     {'name':'b'},
     {'name':'c'}
    ]
  }
</script>

You can check in here https://jsfiddle.net/do68kqje/3/

Sign up to request clarification or add additional context in comments.

2 Comments

I updated it so you have a "hide" array and you can start pushing the index of the element you want to hide
Yes I did, but this package npmjs.com/package/vue2-google-maps it is wrapper to work with vuejs2
0

Not done Vue for a bit, so this may not work, but should be a good pointer.

<template>
    <div v-for="(item, index) in items" v-if="item.shown">
         <span @click="item.shown=false">{{item.name}}</span>
    </div>
</template>
<script>
        export default {
             items: [
                 {'name':'a', shown: true},
                 {'name':'b', shown: true},
                 {'name':'c', shown: true},
             ],
        }
</script>

2 Comments

i fetch this data from api and there is not shown filed i also trying : for (let i of this.items) { i.visible=true; }
@AslanMuhammad-Rza Bit harsh to downvote when that wasn't in the original question.
0

If you don't want to use an other array to keep hide index (like hide :[]) :

new Vue({
    el: "#app",
      data: function() {
    return {
      items:[ {'name':'a'}, {'name':'b'}, {'name':'c'} ]
    }
  },
  methods: {
    setHide: function(item) {
      this.$set(item, 'hide', true);
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.5/vue.js"></script>

<div id="app">
  <div v-for="item in items" :key="item" v-if="!item.hide">
    <span @click="setHide(item)">{{item.name}}</span>
  </div>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.