How does Vue listen for changes in global variables within a component

I have defined a global variable Vue.prototype.url in main.js. The value of this variable is returned in the background. How can I monitor the change of this value in the vue component? Cannot listen using watch

watch: {
  "url"(newVal,oldVal) {
    console.log(newVal,oldVal)
  }
}
Feb.26,2021

you can define it in the data of the root component, and vue will automatically listen


are you sure your way of writing is all right?

watch: {
  'url': function(newVal,oldVal) {
    console.log(newVal,oldVal)
  }
}

have you solved your problem? I have encountered the same situation


ide/state-management.html" rel=" nofollow noreferrer "> https://cn.vuejs.org/v2/guide.

.
Menu