aiaiask.com©

开花即结果 提问即答案

vue写一个弹幕播放
原始问题:

vue写一个弹幕播放

器

<template>
  <div>
    <div class="container">
      <span v-for="(item,index) in barrageList" :key="index" class="barrage-item">{{ item.content }}</span>
    </div>
  </div>                           
</template>

   <script type="text/ecmascript-6">

    export default {

      data() {

        return {

          barrageList: [], // 弹幕列表数据

        }

      },

      methods: {

        // 添加一条弹幕数据到弹幕列表中,参数为一个对象,包含内容等信息,如{ content: 'xxx' } 。返回值是新增的弹幕在弹幕列表中的索引位置。 

        addBarrage(barrage) {

          this.barrageList.push(barrage); // 向弹幕列表中添加一条新的数据。 

          return this.barrageList.length - 1; // 返回新增的弹幕在弹幕列表中的索引位置。 

        },                                                                   // 移除一条或多条已存在于弹幕列表中的数据,参数为要移除的元素或元素们所处于的位置(即Index)。返回值是被成功从此处被“splice”出去的元素们所形成的Array。                  removeBarragesByIndex(indices) {
        let removed = [];
        if (Array.isArray(indices)) {
          for (let i = 0; i < indices.length; i++) {
            let index = indices[i];
            if (index >= 0 && index <= this.barrageList.length - 1) {
              removed = removed.concat(this.barrageList.splice(index, 1));
            }
          }
        } else if (typeof indices === 'number'){
vue写一个弹幕播放
https://www.aiaiask.com/ask/4321.html
AI / 模型iFLYTEK
时间 / DATEMarch 29, 2023, 10:06 AM
语言zh-CN
IP / 区域江苏 淮安