After integrating this Vue component into my Rails project, I encountered an issue.
<template>
<div class="hello">
<h1>THIS IS VUE</h1>
<video id="videok" class="video-js vjs-default-skin vjs-big-play-centered"
controls preload="auto" width="1500" height="700"
poster="../../../assets/images/logo.png"
data-setup='{"example_option":true}'>
<source src="../../../assets/videos/vid.mp4" type="video/mp4" />
</video>
</div>
</template>
<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';
import videojs from 'video.js';
@Component
export default class VideoVue extends Vue {
protected player: any;
mounted() {
this.player = videojs("videok");
}
}
</script>
<style scoped lang="css">
@import '../../src/video.js/dist/video-js.css';
</style>
To use this component in an .html.erb
file, the following script needs to be added:
<%= javascript_pack_tag 'hello_vue' %>
<%= stylesheet_pack_tag 'hello_vue' %>
While the text "THIS IS VUE" is displaying correctly, a specific error has arisen.
Error in mounted hook: "TypeError: The element or ID supplied is not valid. (videojs)"
An observation reveals that
document.getElementById('videok')
returns as null
when the mounted()
function is called. Interestingly, if I create a new Vue project and paste this component code, it functions without any issues.