滚动提示组件

组件

复制代码
<script setup lang="ts">
import { InfoCircleFilled } from '@ant-design/icons-vue';
import { ref, computed, onMounted } from 'vue';

const props = defineProps<{
  dataList?: string[];
}>();

const list = computed(() =>
  props.dataList?.length ? props.dataList : ['暂无预警']
);

const currentIndex = ref(0);

onMounted(() => {
  setInterval(() => {
    currentIndex.value = (currentIndex.value + 1) % list.value.length;
  }, 5000); // 每 5 秒切换一条
});
</script>
<template>
  <div class="tishi-vertical">
    <div class="icon"><InfoCircleFilled />  </div>
    <sapn class="label"> 预警提醒</sapn>
    <div class="labelL">|</div>
    <div class="scroll-box">
      <div class="scroll-list">
        <div class="scroll-item" v-for="(item, index) in list" :key="index">
          {{ item }}
        </div>
        <!-- 关键:复制一遍数据以实现循环无缝 -->
        <div class="scroll-item" v-for="(item, index) in list" :key="'copy-' + index">
          {{ item }}
        </div>
      </div>
    </div>
  </div>
</template>


<style scoped lang="less">
.tishi-vertical {
  margin-left: 25px;
  display: flex;
  align-items: center;
  overflow: hidden;
  font-size: 14px;

  .icon {
    font-size: 20px;
    color: #faad14;
    margin-right: 6px;

    svg {
      path {
        fill: white;
      }
    }
  }

  .labelL {
   margin-right: 20px;
   margin-left: 20px;
  }

  .label {
    margin-right: 8px;
    color: #faad14;
    font-weight: 600;
    font-size: 14px;

  }

  .scroll-box {
    height: 26px * 1; // 同时显示1条
    overflow: hidden;
    flex: 1;
    position: relative;

    .scroll-list {
      display: flex;
      flex-direction: column;
      animation: scroll-up 5s linear infinite; // 控制滚动速度

      .scroll-item {
        height: 24px;
        line-height: 24px;
        white-space: nowrap;
        font-weight: 400;
      }
    }
  }

  @keyframes scroll-up {
    0% {
      transform: translateY(0%);
    }
    100% {
      transform: translateY(-50%); // 滚动一半,前提是数据重复一遍
    }
  }
}

</style>

引入

复制代码
  <!-- 提示 -->
          <WarningNotice :dataList="DATANAMELIST" />

传入数据格式

import { ref, onMounted } from 'vue';

const DATANAMELIST = ref<string[]>([]);

onMounted(() => {

DATANAMELIST.value= ['内容1','内容2','内容3']

});

相关推荐
前端程序猿i10 分钟前
用本地代理 + ZIP 打包 + Excel 命名,优雅批量下载跨域 PDF
前端·javascript·vue.js·html
云间月131412 分钟前
飞算JavaAI智慧文旅场景实践:从景区管理到游客服务的全链路系统搭建
java·开发语言
盖世英雄酱5813612 分钟前
必须掌握的【InheritableThreadLocal】
java·后端
找不到、了18 分钟前
JVM的逃逸分析深入学习
java·jvm
Danny_FD19 分钟前
Vue2 中使用vue-markdown实现编辑器
前端·javascript·vue.js
用户游民19 分钟前
Flutter 项目热更新加载 libapp.so 文件
前端
coding随想19 分钟前
Vue和React对DOM事件流的处理方法解析
前端
用户479492835691520 分钟前
字节面试官:forEach 为什么不能被中断?
前端·javascript
ccnocare21 分钟前
window.electronAPI.send、on 和 once
前端·electron
tager26 分钟前
🍪 让你从此告别“Cookie去哪儿了?”
前端·javascript·后端