1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16@Component 17@Entry 18struct Parent { 19 @State arr: number[] = [1, 2, 3] 20 build() { 21 Column() { 22 Child({items: $arr}) 23 ForEach(this.arr, 24 item => {Text(`${item}`)}, 25 item => item) 26 } 27 } 28} 29 30@Component 31struct Child { 32 @Link items: number[] 33 build() { 34 Column() { 35 Button() { 36 Text("Button1: push") 37 }.onClick(() => { 38 this.items.push(100) 39 }) 40 Button() { 41 Text("Button2: replace whole item") 42 }.onClick(() => { 43 this.items = [100, 200, 300] 44 }) 45 } 46 } 47} 48