Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

PaoloYumul's avatar

Vue JS watch not working

Hello,

I've imported a class 'Hex' and I tried to watch its propery named 'value'. The watcher is not working.

// Hex.js

export default class Hex {
    constructor () {
        this.value = '';
    }
}
// app.js
import Hex from './Hex';

new Vue({
    el: '#app',
    data: {
        // hex has a property called 'value'
        hex: new Hex,
    },

    watch: {
     'hex.value'() {
            alert('This is not triggered');
        }
    }   
});

But when I change hex:new Hex to hex: {value: ''}, the watcher is working.

What could be the problem?

Thanks.

0 likes
3 replies
ahishamali's avatar

you can use the deep watch

watch:{
   hex:{
      deep: true,
      handle(val){
          alert('.....')
      }
   }
}

1 like

Please or to participate in this conversation.