To obtain the original object before it is proxied by the state management framework, call the getTarget API.
Example:
import { UIUtils } from '@kit.ArkUI';
@Observed
class UserInfo {
name: string = 'Tom';
}
@Entry
@Component
struct GetTargetDemo {
@State info: UserInfo = new UserInfo();
build() {
Column() {
Text(`info.name: ${this.info.name}`)
Button('Change the properties of the proxy object')
.onClick(() => {
this.info.name = 'Alice'; // The Text component can refresh
})
Button('Change Original Object Property')
.onClick(() => {
let rawInfo: UserInfo = UIUtils.getTarget(this.info);
if (rawInfo) {
rawInfo.name = 'Bob'; // The Text component cannot be refreshed
}
})
}
}
} Reference