当前位置:网站首页>Do not update the sub component page of parameter object passed from parent to child of nailing applet?

Do not update the sub component page of parameter object passed from parent to child of nailing applet?

2022-06-13 08:08:00 Dark_ programmer

When developing nailing applet , When I come across such a problem .

The... Passed from the parent to the child Values are arrays , Parent component passed setData to update Value time subcomponent No changes in data were detected


The previous usage is as follows :

The parent component uses the child component :

<Child list='{
     {arrayList}}'/>

The parent component updates the data :

data:{
    
	arrayList:[]
}

...

const newList = [1, 2, 3, 4, 5, 6]
this.setData({
    
	arrayList: newList
})

The child component receives the parent component data and stores it in itself data In order to use

The subcomponent receives parameters :

data:{
    
	list: []
}

...

this.setData({
    
	list: this.props.list
})

Use of subcomponents :

	<view a:for="{
     {list}}">
		{
   {item}}
	</view>

After trying , It is modified to use the parent component directly props The data in

Modify the usage as follows :
The subcomponent receives parameters :

props: {
    
	list: ()=>Object;
}

Use of subcomponents :

	<view a:for="{
     {list}}">
		{
   {item}}
	</view>
原网站

版权声明
本文为[Dark_ programmer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206130756432594.html