DOM

  1. <video
  2. @click="togglePlay"
  3. id="video-content"
  4. autoplay="true"
  5. loop="loop"
  6. >
  7. <source src="@/assets/show.mp4" type="video/mp4" />
  8. </video>

视频控制文件

  1. function handleVideo() {
  2. let video = document.getElementById("video-content");
  3. console.log(video, video.autoplay);
  4. if (video.autoplay) {
  5. video.play();
  6. }
  7. }
  8. function togglePlay() {
  9. let videoContent = document.getElementById("video-content");
  10. if (videoContent.paused) {
  11. videoContent.play();
  12. } else {
  13. videoContent.pause();

问题

error: play() failed because the user didn’t interact with the document first

首次渲染不能自动播放, 加入controls控制条才可以通过点击播放,进行视频的操控