I am new to Vue.JS (2) and I am trying to learn components now. I try to use a component in another component with data from a data method (I know you can't use the property Data in a component). My code now:
HTML
<div id="root">
<h1>Tasks</h1>
<list></list>
</div>
JS
Vue.component('list', {
template: '<task v-for="task in tasks">{{ task.task }}</task>',
data: function() {
return {
tasks: [
{task: 'Go to the store', completed: false},
{task: 'Go to the shop', completed: true},
{task: 'Go to the mall', completed: true}
]
};
}
});
Vue.component('task', {
template: '<li><slot></slot></li>'
});
new Vue({
el: '#root'
});
this will return a white screen. If I remove the data, and just use a string in the task template it shows the string, so the component "task" is working in the component "list".
Vue.component('list', {
template: '<task>Test</task>',
});
Vue.component('task', {
template: '<li><slot></slot></li>'
});
new Vue({
el: '#root'
});
So it seems like there is something wrong with displaying the data to the view with the method/data. I've tried many things but I just can't get it right.
Any help would be great, thanks in advance