vue3+ts 左侧是el-steps,右侧是el-card卡片 当左侧点击index第三个的时候,右侧就滚动到卡片的第三个,但是右侧滚动的数据要在顶端,不能在最末端

<template>
  <div>
    <el-steps :active="activeStep" direction="vertical">
      <el-step
        v-for="(step, index) in steps"
        :key="index"
        :title="step.title"
        @click="handleStepClick(index)"
      ></el-step>
    </el-steps>

    <div class="card-container" ref="cardContainer" style="height: 300px; overflow-y: auto;">
      <el-card
        v-for="(card, index) in cards"
        :key="index"
        class="card-item"
        style="height: 200px"
        :id="'card-' + index"
      >
        <template #header>
          <div class="card-header">{{ card.title }}</div>
        </template>
        <div class="card-body">{{ card.content }}</div>
      </el-card>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const steps = ref([{ title: 'Step 1' }, { title: 'Step 2' }, { title: 'Step 3' }]);
const cards = ref([
  { title: 'Card 1', content: 'Content of Card 1' },
  { title: 'Card 2', content: 'Content of Card 2' },
  { title: 'Card 3', content: 'Content of Card 3' },
]);

const activeStep = ref(0);
const cardContainer = ref<HTMLElement | null>(null);

const handleStepClick = (index: number) => {
  activeStep.value = index;
  const targetCard = document.getElementById(`card-${index}`);
  if (targetCard && cardContainer.value) {
    targetCard.scrollIntoView({ behavior: 'smooth', block: 'start' });
  }
};
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值