mai elrefaey
mai elrefaey

Reputation: 392

How to use watch function in typescript language Vuejs?

I need to change this script from js to ts but i need syntax of watchers

export default {
    props: ['branch_id'],
    watch: {}
}

Upvotes: 13

Views: 21666

Answers (1)

Jesper
Jesper

Reputation: 3834

First you have to declare your variable, like myProperty in this case, and then you have to make a @Watch('myProperty') to make the actual watcher for that specific variable.

@Component
export default class App extends Vue {
  myProperty: string

  @Watch('myProperty')
  onPropertyChanged(value: string, oldValue: string) {
    // Do stuff with the watcher here.
  }
}

Upvotes: 24

Related Questions