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

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

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

【问题讨论】:

    标签: typescript vue.js


    【解决方案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.
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 2022-01-24
      • 2017-12-19
      • 2019-01-09
      • 1970-01-01
      • 2021-12-19
      • 1970-01-01
      相关资源
      最近更新 更多