Vue实现点击后文字变色切换

这里用文字举例,图片切换的原理也是一样的

大概思路是:用两个class相同的span分别是切换前后的文字,class相同主要是为了变换前后的文字位置相同。然后用click事件控制它们的显隐。代码如下:

HTML:

<span class="response" v-show="!showCommentInput" @click="showCommentInput = !showCommentInput">回复</span>
<span class="response" v-show="showCommentInput"  @click="showCommentInput = !showCommentInput">回复</span>

JS:

data(){
    return {
        showCommentInput = false,
    }
}

CSS

    .response {
          font-size:14px;
          color: #3e3e3e;
          &:hover{
            font-weight: bold;
          }
          &+.response {
            font-weight: bold;
          }

版权声明:本文为HaiJing1995原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/HaiJing1995/article/details/72844810