I got this vue component in rails.
<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>
I call this component as follows (from a .html.erb
file)
<%= javascript_pack_tag 'hello_vue' %>
<%= stylesheet_pack_tag 'hello_vue' %>
"THIS IS VUE" is rendered fine, but I'm having this error.
Error in mounted hook: "TypeError: The element or ID supplied is not valid. (videojs)"
I have noticed document.getElementById('videok')
is null
at the time mounted()
is triggered. If I do vue create ""new project"
and paste the code of this component it works fine.