question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature request] @Watch multiple properties.

See original GitHub issue

It would be great if we could do:

  @Watch([
    'prop1',
    'prop2',
  ])
  handler() {
    // Do something
  }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

24reactions
kaorun343commented, Jan 21, 2019

@Alendorff

Hi.

vm.$watch can receive a function whereas ComponentOption.watch can’t do so.

https://vuejs.org/v2/api/#watch

@Component
class App extends Vue {
  @Watch('propA', watchOptionsIfNeeded)
  @Watch('propB', watchOptionsIfNeeded)
  watchHandler() {}
}
3reactions
runxc1commented, Dec 4, 2018

So this is actually something that you can do already do in vue.js and it looks like there are a couple different ways to do it.

Below is the discussion on the exact feature request to Vue.js https://github.com/vuejs/vue/issues/844#issuecomment-335026928

It looks like the most document way is to use a function to watch more than one property. https://vuejs.org/v2/api/#vm-watch shows the following example

vm.$watch(
  function () {
    return this.a + this.b
  },
  function (newVal, oldVal) {
    // do something
  }
)

It would be nice to be able to do something like

@Watch(function () {
   return this.a + this.b
 }, "myHandler")
 myHandler(newVal, oldVal) {
   // Do something
 }

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue js watch multiple properties with single handler
So I am having to write the same code multiple times above. Is it possible to simply have all properties being watched and...
Read more >
Deleting multiple properties at once - SmartBear Community
I am using ready api for a quite long time and there was a need to delete multiple properties at single point of...
Read more >
[GA4] About roll-up properties - Analytics Help - Google Support
Roll-up properties provide a broad view of your business across products, brands, or regions by combining data from multiple source properties into a...
Read more >
Feature request: dual sharing - Microsoft Community Hub
Having two people share would be useful. In real life you can have two things in the room to switch between. You need...
Read more >
Feature request tracking for B2B SaaS teams - Savio
Feature requests are saved with the customer, account, and account properties like MRR and Plan; You can quickly see and compare feature requests...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found