Vue自定义组件Props中接收数组

解释这个什么意思具体如下:

 props: {
    content: {
      type: Array,
      // default: function () { return [] }
      default: () => []
    },
}

父组件给子组件的传值:

父组件

里面的返回空,意思就是template里面的div循环每个盒子返回为空盒子,
传给子组件,子组件通过this.$ajax.get({}), 获取数据子组件就能够显示内容在
子组件显示出来了, 这是因为父组件挂载在组件上面

<div class="list" @click="tab_change(index)" v-for="(item,index) in just_for_you_product_type" :key="'type' + index">
		<div class="list_sub_title" :class="{active:tab_index==index}">
</div>

 props: {
    just_for_you_product_type: {
      type: Array,
      // default: function () { return [] }
      default: () => []
    },
}

子组件

<for-you-section @tab_change="tab_change" :just_for_you_product_type="just_for_you_product_type" ></for-you-section>

getJustForYouProduct(){
	this.$ajax.get({
		url:'supplier',	// 假的接口案例
		data:{
			PAGE:1,
			SIZE:10,
		},
		success:res=>{
			this.just_for_you_product = res.data.list;
		}
	})
}

Guess you like

Origin blog.csdn.net/m0_49714202/article/details/117668085