Vue js render video

Asked

Viewed 117 times

1

I have the following component:

<div v-for="video in videos" :key="video.title">
    <video class="video-js" controls preload="auto">
        <source v-bind:src="video.src" type="video/mp4">
    </video>
</div>

script:

<script>
export default {
data: () => ({
    videos: [
      { title: "v1", src: "../../assets/videos/v1.mp4", desc: "v1"},
      { title: "v2", src: "../../assets/videos/v2.mp4", desc: "v2"}
    ]
  })
}
</script>

But the vue.js is not "converting" the video path.

When using <source src="../../assets/videos/v1.mp4" type="video/mp4"> in my html looks like this: <source src="/static/media/v1.dc6c1ef.mp4" type="video/mp4">.

How can I have a array link and do the bind with the vue.js correctly?

1 answer

2


Try it like this:

import v1 from "../../assets/videos/v1.mp4";
import v2 from "../../assets/videos/v2.mp4";

export default {
data: () => ({
    videos: [
      { title: "v1", src: v1, desc: "v1"},
      { title: "v2", src: v2, desc: "v2"}
    ]
  })
}
  • Perfect!! worked.. would have to import several videos using one import only?

  • 1

    I don’t know, I don’t think so. In a loop, I think you can use requires. Even import might work in a loop, I’ve never tried.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.