vue父组件怎么样向子组件传递data

LIANGWEIBIAO
  • 63

父组件

//向子组件传递父组件data中的items
<ForecastList items='items'></ForecastList>

 data: function () {
            return {
                items: [
                    {message: 'foo' },
                    {message: 'Bar' }
                ]
            };

子组件接收得不到父组件中的items,父组件传递数据格式写错了吗?

    props: ['items'],
    mounted:function(){
      console.log(this.items)
    }
回复
阅读 1.8k
2 个回答
<div id="demo">
        <todo-item v-for="item in list" :a="item"></todo-item>
    </div>

Vue.component('todo-item',{
            props: ['a'],
            template: '<div>{{ a.text }}</div>'
        })

var vm = new Vue({
            el: '#demo',
            data: {
                list: [
                    { text: 'Learn JavaScript' },
                    { text: 'Learn Vue' },
                    { text: 'Build something awesome' }
                ]
            }
        })
宣传栏