In connection to the question I asked here, I have realised that my issue maybe because the template is being loaded before the script and when it gets an error that the variable is not defined, it stops the script from running. If that is the case then it's maybe because of use strict which is somewhere in my node_modules and not in my code.
My components look like this:
<style lang="sass">
.hero {
color: white;
padding-top: 10em;
}
.image {
background: no-repeat;
background-size: 100% 100%;
height: 600px;
box-shadow:inset 0 0 0 2000px rgba(0,0,50,0.3);
}
</style>
<template>
<div :style="{ backgroundImage: 'url(' + components.carousel.content.image + ')' }" class="image">
<div class="row hero">
<div class="small-8 medium-6 columns">
<h2>Welcome to <strong>{{components.site.name}}</strong>
<br/> {{components.carousel.content.tag_line}}</h2>
<br>
<p>
{{components.carousel.content.perks_1}} |
{{components.carousel.content.perks_2}} |
{{components.carousel.content.perks_3}}
</p>
</div>
</div>
</div>
</template>
<script>
import homepageMixin from '../mixin';
export default {
mixins: [homepageMixin],
data: function () {
return {
components: ''
}
}
}
</script>
When I load I get this error:
[Vue warn]: Error when rendering component carousel: ...
vue.js?3de6:2229 Uncaught TypeError: Cannot read property 'content' of undefined
I had been using it like that for a long time as it was loading the data after and replacing it in the template, but after I tried to install babel, it somehow enforces use strict now. When I check the difference between the compiled JS file before and after I realise that this line was at the bottom but now its being compiled at the top before my components.
var g;\r\n\r\n// This works in non-strict mode\r\ng = (function() { return this; })();
A solution would be to load the script first so the by the time the template is loaded the the data is available. How can I do that?