利用click事件和v-show实现点击切换

目标:利用click点击事件和v-show实现点击图片和文字的切换。

初始:

 实现的效果:点击最右侧出现如下展示效果,再次点击恢复上图效果

 实现方法:

template中:

<div class="resultType ">
                        <span class="resultTypeTitle">我的偶像</span>
                        <span class="paintWord" v-show="isShowPaintWordOne">
                            我的偶像是千玺
                        </span>
                        <span
                            class="paintWordFinish"
                            v-show="isShowPaintWordFinishOne"
                        >
                            偶像最棒&nbsp;&nbsp;&nbsp;√
                        </span>
                        <img
                            src="./theme/img/editWhite.png"
                            @click="finishPaintOne"
                            v-show="isShowPaintWordOne"
                        />
                        <img
                            src="./theme/img/editBlue.png"
                            @click="finishPaintRecoverOne"
                            v-show="isShowPaintWordFinishOne"
</div>

script的data中:

isShowPaintWordOne: true,
isShowPaintWordFinishOne: false,

script的methods中:

finishPaintOne() {
            this.isShowPaintWordOne = false;
            this.isShowPaintWordFinishOne = true;
        },
finishPaintRecoverOne() {
            this.isShowPaintWordOne = true;
            this.isShowPaintWordFinishOne = false;
        },

样式css:

.resultType {
                width: 361px;
                height: 41px;
                background-color: #242e3a;
                display: flex;
                align-items: center;
                margin-bottom: 10px;
                border-bottom: 1px solid #1a446a;
                .resultTypeTitle {
                    flex-basis: 100px;
                    justify-content: center;
                    font-size: 12px;
                    font-family: Source Han Sans CN, Source Han Sans CN-Regular;
                    font-weight: 500;
                    text-align: left;
                    color: #b0d9ff;
                    padding-left: 20px;
                }
                .paintWord {
                    opacity: 0.3;
                    font-size: 12px;
                    font-family: Source Han Sans CN, Source Han Sans CN-Regular;
                    font-weight: 400;
                    text-align: left;
                    color: #ffffff;
                    width: 214px;
                }
                .paintWordFinish {
                    font-size: 12px;
                    font-family: Source Han Sans CN, Source Han Sans CN-Regular;
                    font-weight: 400;
                    text-align: left;
                    color: #7effbe;
                    width: 214px;
                }
}

这样就实现了利用click点击事件和v-show实现点击图片和文字的切换。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值