Watch route changes in Vue.js with Typescript

笑着哭i 提交于 2019-12-10 02:39:39

问题


I'd like to detect changes in my URL in a Vue.js application using TypeScript. In JavaScript this can be done as follows:

watch: {
  '$route': {
     handler: 'onUrlChange',
     immediate: true,
     deep: true
   }
},

onUrlChange(newUrl){
   // Some action
}

How could I do the same in TypeScript?


回答1:


I found the solution here: https://github.com/kaorun343/vue-property-decorator

It can be done like this:

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


来源:https://stackoverflow.com/questions/51892100/watch-route-changes-in-vue-js-with-typescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!