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

(编辑:jimmy 日期: 2024/9/27 浏览:2)

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

大概思路是:用两个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;
 }

以上这篇Vue实现点击后文字变色切换方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。