如何在打字稿语言Vuejs中使用监视功能?

时间:2019-12-19 10:43:27

标签: typescript vue.js

我需要将此脚本从js更改为ts,但我需要观察者的语法

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

1 个答案:

答案 0 :(得分:0)

首先,您必须声明您的变量,例如myProperty,然后必须创建一个@Watch('myProperty'),以使该变量真正成为观察者。

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

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