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

Posted

技术标签:

【中文标题】如何在打字稿语言Vuejs中使用watch功能?【英文标题】:How to use watch function in typescript language Vuejs? 【发布时间】:2020-04-11 22:50:22 【问题描述】:

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

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

【问题讨论】:

【参考方案1】:

首先你必须声明你的变量,例如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.
  

【讨论】:

以上是关于如何在打字稿语言Vuejs中使用watch功能?的主要内容,如果未能解决你的问题,请参考以下文章