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

父组件

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

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

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

    props: ['items'],    mounted:function(){      console.log(this.items)
    }


慕容3067478
浏览 469回答 1
1回答

POPMUISE

<div id="demo">&nbsp; &nbsp; &nbsp; &nbsp; <todo-item v-for="item in list" :a="item"></todo-item>&nbsp; &nbsp; </div>Vue.component('todo-item',{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; props: ['a'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; template: '<div>{{ a.text }}</div>'&nbsp; &nbsp; &nbsp; &nbsp; })var vm = new Vue({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; el: '#demo',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; list: [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { text: 'Learn JavaScript' },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { text: 'Learn Vue' },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { text: 'Build something awesome' }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; })
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript