I'm a Vue beginner and struggling with how to use one component within the template of another or how to combine them in HTML. I've tried looking through the documentation and Stack Overflow but can't seem to figure it out.
Currently, I am using Vue via cdnjs.
For example:
I have a root Vue instance #app. Inside, I've registered two data arrays: one for containers and another for tables within those containers.
Now, in my HTML, I have a container where I want to include a table at a specific place. How do I achieve this? When I try to put the table directly inside the container component, Vue doesn't recognize it as valid and throws an error.
Here is my progress so far:
var app = new Vue({
el: '#app',
data: {
containersList: [{container-object}],
tablesList: [],
methods(){}
},
let container = Vue.component('container',{
props: ['item'],
template: '<div class="container">{{ item.data }}</container></div>',
<container v-for="item in containerList></container>
At this point, I have managed to render components, populate them with data, and make everything reactive.
My next challenge is populating containers with tables and potentially nesting tables within tables. Any advice on how to approach this?
My current logic seems to be failing here.
let tableComponent = Vue.component('table-component', {
props: ['item'],
template: '<div class="table"></div>'
}
let container = Vue.component('container',{
props: ['item'],
template: '<div class="container"><table-component></table-component></div>
UPDATE: Although the rendering appears as expected, I am encountering an error related to the "tablesList" array in the data. It seems that the child component does not have access to it and throws the error "Property or method 'tablesList' is not defined on the instance but referenced during render".
The parent container component has access to it, but the child component does not.