1# ArkUI子系统Changelog 2 3## cl.arkui.1 当使用双向绑定范式并给对应的@Event赋值时编译报错变更 4 5**访问级别** 6 7公开接口 8 9**变更原因** 10 11双向绑定语法和@Event接口不兼容,需要增加编译器校验。 12 13**变更影响** 14 15该变更为不兼容变更。 16 17举例说明,执行以下用例: 18 19```ts 20@Entry 21@ComponentV2 22struct EventExample { 23 @Local value: string = 'Hi !'; 24 25 build() { 26 Column() { 27 Text(this.value) 28 .fontSize(50) 29 .fontColor(Color.Red) 30 Star({ value: this.value!!, $value: (val: string) => { this.value += val; }}) 31 } 32 } 33} 34 35@ComponentV2 36struct Star { 37 @Param value: string = 'Hi !'; 38 @Event $value: (val: string) => void = (val: string) => {}; 39 40 build() { 41 Column() { 42 Text(this.value) 43 .fontSize(50) 44 Button('click me to change value') 45 .onClick(() => { 46 this.$value('hello'); 47 }) 48 } 49 } 50} 51``` 52 53变更前:编译运行不报错,点击Button,父子组件的Text组件文本内容均变为"hello",开发者传入的对应的@Event方法不生效。 54 55变更后:检测到开发者使用了双向绑定范式并且给对应的@Event方法赋值,编译拦截报错。 56 57**起始API Level** 58 59API 12 60 61**变更发生版本** 62 63从OpenHarmony SDK 5.1.0.43开始。 64 65**变更的接口/组件** 66 67!!双向绑定语法,@Event装饰器。 68 69**适配指导** 70 71当使用双向绑定范式并给对应的@Event方法赋值时,编译报错,删掉给对应的@Event方法的传参即可解决。 72 73修改前: 74 75使用双向绑定范式this.value!!,同时给对应的$value方法传递参数$value: (val: string) => { this.value += val; }。 76 77```ts 78@Entry 79@ComponentV2 80struct EventExample { 81 @Local value: string = 'Hi !'; 82 83 build() { 84 Column() { 85 Text(this.value) 86 .fontSize(50) 87 .fontColor(Color.Red) 88 Star({ value: this.value!!, $value: (val: string) => { this.value += val; }}) 89 } 90 } 91} 92 93@ComponentV2 94struct Star { 95 @Param value: string = 'Hi !'; 96 @Event $value: (val: string) => void = (val: string) => {}; 97 98 build() { 99 Column() { 100 Text(this.value) 101 .fontSize(50) 102 Button('click me to change value') 103 .onClick(() => { 104 this.$value('hello'); 105 }) 106 } 107 } 108} 109``` 110 111修改后: 112 113删除给对应的$value方法传递的参数。 114 115```ts 116@Entry 117@ComponentV2 118struct EventExample { 119 @Local value: string = 'Hi !'; 120 121 build() { 122 Column() { 123 Text(this.value) 124 .fontSize(50) 125 .fontColor(Color.Red) 126 Star({ value: this.value!! }) 127 } 128 } 129} 130 131@ComponentV2 132struct Star { 133 @Param value: string = 'Hi !'; 134 @Event $value: (val: string) => void = (val: string) => {}; 135 136 build() { 137 Column() { 138 Text(this.value) 139 .fontSize(50) 140 Button('click me to change value') 141 .onClick(() => { 142 this.$value('hello'); 143 }) 144 } 145 } 146} 147``` 148 149## cl.arkui.2 装饰器@Computed编译在特定场景下新增两个ERROR报错提示 150 151**访问级别** 152 153公开接口 154 155**变更原因** 156 157@Computed不能和双向绑定!!连用,@Computed装饰的是getter访问器,不会被子组件同步,也不能被赋值。开发者自己实现的计算属性的setter不生效,且产生编译时报错。 158 159**变更影响** 160 161此变更不涉及应用适配。 162 1631. 当@Computed装饰的属性和双向绑定范式一起使用时,编译时ERROR报错提示 164 165```ts 166@Entry 167@ComponentV2 168struct TestComputed { 169 @Local str: string = 'hello,world' 170 171 @Computed 172 get strFun() { 173 return this.str 174 } 175 176 build() { 177 Scroll() { 178 Column() { 179 Text(this.str) 180 Child({ childStr: this.strFun!! }) 181 } 182 } 183 } 184} 185 186@ComponentV2 187struct Child { 188 @Param childStr: string = 'childStr' 189 @Event $childStr: (val: string) => void 190 191 build() { 192 Column() { 193 Button('ChildChange') 194 .onClick(() => { 195 this.$childStr('newStr') 196 }) 197 } 198 } 199} 200``` 201 202变更前:编译时不报错 203 204变更后:编译时报错 205 206``` 207A property decorated by '@Computed' cannot be used with two-bind syntax. 208``` 209 2102. @Computed装饰的get属性方法,不能写set方法,编译进行ERROR报错提示 211 212```ts 213@Entry 214@ComponentV2 215struct TestComputed { 216 @Local str: string = 'hello,world' 217 218 @Computed 219 get strFun() { 220 return this.str 221 } 222 223 set strFun(value: string) { 224 this.str = value 225 } 226 227 build() { 228 Scroll() { 229 Column() { 230 Text(this.str) 231 } 232 } 233 } 234} 235``` 236 237变更前:编译时不报错 238 239变更后:编译时报错 240 241``` 242A property decorated by '@Computed' cannot define a set method. 243``` 244 245**起始API Level** 246 247API 12 248 249**变更发生版本** 250 251从OpenHarmony SDK 5.1.0.43开始。 252 253**变更的接口/组件** 254 255@Computed 256 257**适配指导** 258 259默认行为变更,无需适配,但应注意变更后的行为是否对整体应用逻辑产生影响。