Observe model properties using Vue 3 and Typescript
P粉143640496
P粉143640496 2023-09-02 23:07:50
0
1
614
<p>I'm trying to monitor my Typescript model properties and it works but gives a warning in the console and I can't find how to remove it. </p> <p>This is my Typescript model: </p> <pre class="brush:php;toolbar:false;">import { watch, ref, Ref, reactive } from 'vue' export default class Resa { public id: Number = 0 public deferred_invoicing: Ref<Boolean> = ref(false) constructor(properties?: Object) { watch(this.deferred_invoicing, (newValue, oldValue) => { console.log(newValue) } } }</pre> <p>The watch is working fine, but I have this warning in the console<code>[Vue warn]: Invalid watch source: false A watch source can only be a getter/effect function, a ref, a reactive object , or an array of these types.</code></p> <p>Did I do something wrong? </p> <p>I have tried using the string <code>'deferred_invoicing'</code> instead of <code>this.deferred_invoicing</code></p>
P粉143640496
P粉143640496

reply all(1)
P粉512363233

Your class instance is set to Reactive somewhere, making its deferred_invoicing attribute unreferenceable

use

watch(toRaw(this).deferred_invoicing, (newValue, oldValue) => {
      console.log(newValue)
    }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template