真是血的教训啊 搞了一天
最近在用3.2做项目。
在项目中使用 videojs 但是一直有问题就是传ref过去但是找不到video的标签
<template>
<div class="content">
<video id="videoPlayer" ref="videoPlayer" class="video-js"></video>
</div>
</template>
<script setup>
import { ref } from 'vue'
const videoPlayer = ref(null)
console.log(videoPlayer.value) // unidefined
</script>
<style lang="scss" scoped>
.content{
width: 100%;
height: 100vh;
min-width: 1200px;
video{
width: 100%;
height: 100%;
}
}
</style>
原因:vue生命周期
因为生命周期的问题,vue3中依旧生命周期。只是setup中封装了beforeCreate和created, 所以只要在虚拟dom挂载后再去获取到dom就可以解决。
</