代码之家  ›  专栏  ›  技术社区  ›  luthien

使用Typescript监视Vue.js中的路由更改

  •  6
  • luthien  · 技术社区  · 8 年前

    watch: {
      '$route': {
         handler: 'onUrlChange',
         immediate: true,
         deep: true
       }
    },
    
    onUrlChange(newUrl){
       // Some action
    }
    

    我怎么能在打字稿上做同样的事呢?

    1 回复  |  直到 8 年前
        1
  •  17
  •   luthien    8 年前

    我在这里找到了解决办法: https://github.com/kaorun343/vue-property-decorator

    可以这样做:

       @Watch('$route', { immediate: true, deep: true })
       onUrlChange(newVal: any) {
          // Some action
        }