1

I have a list of tags and a list of selected tags:

data () {
    return {
        tags: ['#tag1', '#tag2', '#tag3'],
        selectTags: ['#tag1', '#tag2', '#tag3'],
        images: {}
    }
},

With them, I created a checkbox loop:

<div v-for="tag in tags" :key="tag">
    <input type="checkbox" :id="tag" :value="tag" v-model="selectTags" checked>
    <label :for="tag">{{ tag }}</label>
</div>

This tags is used as keys in a list of images. I would like to show/hide image based on select Tags list. If this image key in on the list, the image show. Otherwise, it's will be hidden.

<template v-for="(tag, index) in images" v-show="selectTags.includes(index)">
    <figure class="thumb" v-for="path in tag['best']['paths']" :key="path">
        <img :src="path | formatImageURL" alt="">
    </figure>
</template>

This not works when page loaded and when I uncheck a tag.

1
  • 1
    your v-model is set to an array on the checkbox, so if you check that checkbox, selectTags will be set to true. Commented Nov 21, 2019 at 13:28

1 Answer 1

1

You cannot use the v-show directive on a template element, it will have no effect. You need to use it on the child element contained within it, in your case the figure element.

See relevant official doc here:

Note that v-show doesn’t support the <template> element, nor does it work with v-else.

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

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.