Hey there!
Check out this snippet of HTML code:
// index.html
<div data-init="component-one">
<...>
<div data-init="component-two">
<button @click="doSomething($event)">
</div>
</div>
This part basically involves referencing a Vue instance within another Vue instance. The JavaScript code for this is divided into two files, which are structured like so:
// componentOne.js
new Vue(
el: '[data-init="component-one"]',
data: {...},
methods: {...}
);
// componentTwo.js
new Vue(
el: '[data-init="component-two"]'
data: {...}
methods: {
doSomething: function(event) {...}
}
);
The issue I'm encountering here is that the doSomething
method from componentTwo
isn't being called.
However, when I include some inline content like {{ 3 + 3 }}
, it functions as expected. Vue seems to recognize that something exists in that area. Additionally, the @click
element disappears upon page load.
I experimented with using inline-template
, but it didn't produce the desired outcome in this particular scenario. It seems like it's not suitable for this case, so I abandoned that approach.
What would be the best way to tackle this situation? And how can I ensure everything works smoothly with the current setup?
We're working with Vue version 2.1.8
.
Cheers!