2016-10-18 21 views
0

VueインスタンスからVueコンポーネントにデータを渡すにはどうすればよいですか?私はここでfiddleVueインスタンスからVueコンポーネントにデータを渡す

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スクリプト

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

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

が持っているもの残念ながらですが、私のコンポーネントテンプレート内に存在する '李' に 'V-のための' を実行しようとしています私はこれまでに試してみました(私のフィドルを参照してください)は動作していない、任意の助けてください? [vue.js内のコンポーネントにデータを渡す]の

+0

可能な複製(http://stackoverflow.com/questions/34534151/passing-data-to-components-in- vue-js) –

答えて

0

が、私は自分のコード更新

<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'] 
    } 
}); 
関連する問題