美文网首页
vue 循环动态设置ref并获取$refs

vue 循环动态设置ref并获取$refs

作者: 少年眼蓝不及海 | 来源:发表于2021-04-21 15:26 被阅读0次
    <el-carousel-item v-for="(item, index) in items" :key="item">
                    <img v-if="isImgItem(item)" class="item" :key="'item'+index" :src="item" width="100%" />
                    <video-player v-else class="video-player vjs-custom-skin" 
                        :ref="'videoPlayer'+index" 
                        :key="'item'+index"
                        :playsinline="true" 
                        :options="playerOptions"
                        @ended="onPlayerEnded($event)"
                        >
                    </video-player>
                    <!-- <video v-else controls autoplay :key="index" class="item" type="video/mp4" :src="item" width="100%"></video> -->
                </el-carousel-item>
              
    
                this.playerOptions.sources[0].src = item;
                let videoPlayer = eval("this.$refs.videoPlayer" +index)[0];
                videoPlayer.player.play();
    

    相关文章

      网友评论

          本文标题:vue 循环动态设置ref并获取$refs

          本文链接:https://www.haomeiwen.com/subject/dxlzlltx.html