路由跳转传参或携带id和name值 & 实现title的hover变蓝效果

路由跳转传参或携带id和name值 & 实现title的hover变蓝效果

一、路由跳转传参或携带id和name值

1、第一种写法
结构
<div class="p-aq" @click="openCommon(item_q.item)">
    <span>{{item_q.item.question}}</span>
</div>


created() {
    // 获取问题详情数据
    this.getDeta()
},
方法
openCommon(item) {
    this.$router.push({ path: '/common', query: { id: item.id } })
},
2、第二种写法
结构
<div
     class="a-count"
     v-for="(item,index) in detaList.related_interpretation"
     :key="index"
     @click="openExplain(item.id)"
     :class="{'active-bg':curBg===index}"
     @mouseover="curBg=index"
     >{{item.title}}</div>
</div>

方法
// 打开具体内容
openExplain(id) {
    this.$router.push({ path: '/explain', query: { id: id } })
},
    
     // get请求 get('地址','{params:数据}')
    async getDeta() {
      let res = await this.$http.get('/FAQ/detail', {
        id: this.$route.query.id,
      })

      if (res.code != 200) {
        this.$router.push('/404')
      } else {
        this.detaList = res.result
      }
    },

二、实现title的hover变蓝效果

data(){
    return{
      curBg: -1, 
           // 问题详情
      // contact: [],
      detaList: {
        related_interpretation: [],
        related_question: [],
        related_law: [],
      },
    }
}

样式

// 滑动变色
.active-bg {
  &:hover {
    color: #0084ff;
  }
}

第一种写法样式

.p-aq {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    // height: 28px;
    font-size: 18px;
    color: #333333;
    font-weight: bold;
    line-height: 28px;
    span {
        cursor: pointer; /*鼠标悬停变小手*/
    }
    span:hover {
        color: #1890ff;  /*hover变蓝*/
    }
}

第二种写法样式

.p-aq {
    height: 22px;
    font-size: 16px;
    color: #333333;
    // font-weight: bold;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    span {
        cursor: pointer; /*鼠标悬停变小手*/
    }
}

图例

在这里插入图片描述

<div class="a">
    <div class="a-a">
        <div class="a-tit">相关解读</div>
        <div class="a-count-no" v-if="detaList.related_interpretation=='-'">
            <p>暂无相关解读</p>
        </div>
        <div v-else>
            <div
                 class="a-count"
                 v-for="(item,index) in detaList.related_interpretation"
                 :key="index"
                 @click="openExplain(item.id)"
                 >{{item.title}}</div>
        </div>
    </div>
</div>

样式

.a {
    // height: 178px;
    padding: 16px 20px 4px 20px;
    background: #ffffff;
    border-radius: 4px;
    .a-tit {
        font-size: 18px;
        color: rgba(0, 0, 0, 0.85);
        line-height: 22px;
        font-weight: bold;
        margin-bottom: 16px;
    }
    .a-count {
        font-size: 16px;
        color: #555555;
        line-height: 22px;
        margin-bottom: 16px;
        cursor: pointer;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2; // 控制多行的行数
        -webkit-box-orient: vertical;
    }
    .a-count-no {
        font-size: 16px;
        color: #555555;
        line-height: 22px;
        margin-bottom: 16px;
    }
    .a-count:hover {
        color: #0084ff;
    }
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值