I'm getting crazy on this.
This is the code, is a component I'm using inside a form to show the preview of a video when I paste an url into an input:
<template>
<div class="row">
{{embedData}}
<input v-model="embedData" name="content[body]" id="content_body">
<div class="col-md-6">
<div class="form-group">
<div class="form-group url optional content_video_url form-group-valid">
<label for="content_video_url" class="url optional">Url del video</label>
<input @change="forceRerender" v-model="url" type="url" value="" name="content[video_url]" id="content_video_url" class="form-control is-valid string url optional">
</div>
</div>
</div>
<div class="col-md-6">
<div class="video-responsive"
<o-embed ref="embed" :url="url" :key="componentKey"></o-embed>
</div>
</div>
</div>
</template>
<script>
import oEmbed from './oEmbed'
import EventBus from '../utils/eventBus'
export default {
components: {
oEmbed
},
props: {
video_url: String,
video_caption: String
},
created: function() {
this.url = this.video_url;
this.caption = this.video_caption;
},
mounted: function() {
EventBus.$on('HTML', function (payLoad) {
this.embedData = payLoad
console.log('payLoad:' + this.embedData);
console.log('arrived');
});
},
data: function() {
return {
url: '',
caption: '',
componentKey: 0,
embedData: ''
}
},
methods: {
forceRerender () {
this.componentKey = this.componentKey + 1;
}
}
}
</script>
o-embed is a component, and I've added a simple bus emit function when the component is update:
mounted: function() {
EventBus.$on('HTML', function (payLoad) {
this.embedData = payLoad
console.log('payLoad:' + this.embedData);
});
}
If I check the console log I have this
payLoad: <iframe src="https://player.vimeo.com/video/596287904?app_id=122963&h=d77f5dc57c" width="426" height="240" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen title="Raritan Bay Cruisers-Hopelawn New Jersey CruisebNight 8-31-2021.wmv"></iframe>
Everythink is working, this.embedData looks ok, I have the log, but when I render embedData in my view it's empty.
I give an additional info: I'm forcing the re-rendering of the embed component, but I don't think it's related.
Any ideas?
componentKeywill rerender everything. I thought Vue just rerenders portions of the template where data (or values depending on it) are used. How about forcing Vue re-render the right way