vue2的$refs可以获取dom节点,如下
// html
<video ref="video"></video>
// js
this.$nextTick(() => {
const myVideo = this.$refs.video
myVideo.play()
})但是vue3没有this,所以不能这么使用,可以用下面的方式实现:
// html
<video ref="video"></video>
// js
import { ref, nextTick } from 'vue'
const video = ref(null) // 注意这里的变量名video要和html中的ref一致
this.$nextTick(() => {
// video.value就是获取的dom
video.value.play()
})