0
votes

How can I pass the data from the Vue instance to the Vue component? I'm trying to do 'v-for' on a 'li' that resides in my component template, here's the fiddle

HTML

<div id="app">
    <my-notification></my-notification>
</div>

<template id="my-template">
    <ul>
        <li v-for="nn in notifications">{{ nn }}</li>
    </ul>
</template>

Vue script

Vue.component('my-notification',{
    template : '#my-template',
});

new Vue({
    el : '#app',
    data : {
        notifications : ['notification 1','notification 2','notification 3']
    }
});

Unfortunately what have I tried so far (see my fiddle) is not working, any help please?

2

2 Answers

1
votes

You can also consider vuex if your application get bigger

0
votes

I updated my code

<div id="app">
    <my-notification :notification="notifications"></my-notification>
</div>

<template id="my-template">
    <ul>
        <li v-for="nn in nns">{{ nn }}</li>
    </ul>
</template>

Vue.component('my-notification',{
    template : '#my-template',
    props : ['notification'],
    data : function(){
        return {
            nns : this.notification
        }
    }
});

new Vue({
    el : '#app',
    data : {
        notifications : ['notification 1','notification 2','notification 3']
    }
});