0

I have this code:

export default class Some{
    private isUpdating: Ref<boolean> = ref(false)
    ....
    constructor() {
        console.log(this.isUpdating) //it shows RefImpl
    }
    async update() {
         console.log(this.isUpdating) //it shows simple boolean...
         this.isUpdating.value = true //...so this causes error
         ...some work
         this.isUpdating.value = false
    }
}

There no other modifications of this variable. Tried also initialize it in constructor method, but result is always the same: in constructor this variable is ref, after initialization it becomes simple boolean. Where am i wrong?

looqey
  • 3
  • 4
  • 2
    This is a known class pitfall. Avoid using this in constructor and refs. You can use a ref as native private # field in order to not unwrap it. I'd suggest to not use reactive classes at all as Vue isn't suited well. See https://stackoverflow.com/a/76247596/3731501 for an overview – Estus Flask Jun 02 '23 at 07:23

0 Answers0