vue.js - 尝试使用vue js隐藏和显示图标
问题描述
我试图在点击时隐藏并显示一个很棒的字体 5 图标。值在场景后面发生变化,但图标没有被更改。我已经尝试过 vue js 必须提供的其他类绑定,但它产生了相同的结果。
<template>
....
<a href="#" class="social-button" @click.prevent="showAttribute(index)" rel="tooltip" data-color-class="primary" data-animate="animated fadeIn" data-original-title="" data-toggle="tooltip" data-placement="bottom">
<i class="fa fa-eye" v-if="category.attributes[index].show"></i>
<i class="fa fa-eye-slash" v-else></i>
</a>
....
</template>
<script>
export default {
...
showAttribute(index){
this.category.attributes[index].show = !this.category.attributes[index].show;
},
...
}
</script>
解决方案
试试这个v-if="!category.attributes[index].show"而不是 v-else
<template>
....
<a href="#" class="social-button" @click.prevent="showAttribute(index)" rel="tooltip" data-color-class="primary" data-animate="animated fadeIn" data-original-title="" data-toggle="tooltip" data-placement="bottom">
<i class="fa fa-eye" v-if="category.attributes[index].show"></i>
<i class="fa fa-eye-slash" v-if="!category.attributes[index].show"></i>
</a>
....
</template>
<script>
export default {
...
showAttribute(index){
this.category.attributes[index].show = !this.category.attributes[index].show;
},
...
}
</script>
如果您没有获得该值或获得的值为 null,则 onPage 加载。然后,您需要在 data() 中设置默认值
推荐阅读
- python - 带有 wolfram alpha api 的 Discord 机器人无法正常工作
- android - 任务 ':launcher:bundleReleaseResources' 执行失败
- c# - 如何确保仅在返回 api 结果时才继续执行网页?
- python - 从递归函数返回值的错误
- android - 开发客户端:找不到原生 iOS 和 Android 项目的通用 URI 方案
- audio - 如何解码原始 f32 音频样本,以便提取特定频率的音量?
- excel - 如何使用 Excel VBA 中的图标(形状)在月份之间导航?
- amazon-web-services - AWS ECS 不支持在 docker compose 中部署标签
- flutter - 为什么我不能在 GestureDetector 下使用 setState
- angular - Angular NativeScript 使用 AuthGuard 保护选定的选项卡