javascript - 根据数组列表显示/隐藏图像
问题描述
我有一个标签列表和一个选定标签列表:
data () {
return {
tags: ['#tag1', '#tag2', '#tag3'],
selectTags: ['#tag1', '#tag2', '#tag3'],
images: {}
}
},
有了它们,我创建了一个复选框循环:
<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>
此标签用作图像列表中的键。我想根据select Tags
列表显示/隐藏图像。如果此图像在列表中键入,则图像显示。否则,它将被隐藏。
<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>
这在页面加载和取消选中标签时不起作用。
解决方案
您不能v-show
在元素上使用该指令template
,它将无效。您需要在其中包含的子元素上使用它,在您的情况下是figure
元素。
在此处查看相关的官方文档:
请注意,v-show 不支持该
<template>
元素,也不适用于 v-else。
推荐阅读
- c++ - 如何创建源代码存储在子目录中的 CMake 库?
- django - Django:如何防止经过身份验证的用户在 Django-registration-redux 中注册和登录页面
- angular - 编译打字稿时未初始化变量的不太严格的模式
- java - 多个服务器也是客户端 - JAVA 中的通信
- java - 如何在递归堆栈之间移动元素?
- c# - 以“一劳永逸”的方式创建异步请求执行
- assembly - CPU在执行某些指令时是否关心DPL和RPL?
- c# - 如何使用 FromQuery 传递复杂的 C# 对象
- c# - 将哈希字符串值转换为 SHA256
- kubernetes - 在 Job pod 中的容器退出并且 sidecar 容器仍在运行后,网络端点被禁用