滚动提示组件

组件

复制代码
<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']

});

相关推荐
我爱挣钱我也要早睡!7 分钟前
Java 复习笔记
java·开发语言·笔记
牧羊狼的狼1 小时前
React 中的 HOC 和 Hooks
前端·javascript·react.js·hooks·高阶组件·hoc
AD钙奶-lalala2 小时前
Mac OS上搭建 http server
java
知识分享小能手3 小时前
React学习教程,从入门到精通, React 属性(Props)语法知识点与案例详解(14)
前端·javascript·vue.js·学习·react.js·vue·react
luckys.one3 小时前
第9篇:Freqtrade量化交易之config.json 基础入门与初始化
javascript·数据库·python·mysql·算法·json·区块链
魔云连洲3 小时前
深入解析:Vue与React的异步批处理更新机制
前端·vue.js·react.js
mCell3 小时前
JavaScript 的多线程能力:Worker
前端·javascript·浏览器
weixin_437830945 小时前
使用冰狐智能辅助实现图形列表自动点击:OCR与HID技术详解
开发语言·javascript·ocr
超级无敌攻城狮5 小时前
3 分钟学会!波浪文字动画超详细教程,从 0 到 1 实现「思考中 / 加载中」高级效果
前端
excel5 小时前
用 TensorFlow.js Node 实现猫图像识别(教学版逐步分解)
前端