一 使用插件

vue3-danmaku

https://github.com/hellodigua/vue-danmaku/tree/vue3
npm install vue3-danmaku --save

做了一个简单demo

 

<template>
  <div class="baberrage">
    <vue-danmaku class="danmaku" ref="danmakuRef" v-model:danmus="danmus" useSlot loop :speeds="100" :channels="4">
      <template v-slot:dm="{ danmu }">
        <div class="danmaku-name">{{ danmu }}</div>
      </template>
    </vue-danmaku>
  </div>
</template>

<script lang="ts" setup>
import vueDanmaku from 'vue3-danmaku'
import { ref } from 'vue'

const danmus = ref(['danmu1', 'danmu2', 'danmu3', 'danmu4', 'danmu5', 'danmu6', 'danmu7', 'danmu8'])
</script>

<style lang="less" scoped>
.baberrage {
  width: 100%;
  height: 400px;
  background: rebeccapurple;
  .danmaku {
    width: 100%;
    height: 100%;
    &-name {
      width: 150px;
      height: 20px;
      background: darkblue;
      margin-right: 20px;
    }
  }
}
</style>

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐