FAQ: Vue Data - Watchers

This community-built FAQ covers the “Watchers” exercise from the lesson “Vue Data”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Vue.js

FAQs on the exercise Watchers

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Good Morning.
How can I decide when I have to use ‘watch’ propierties? I’ve understood that I’ve have to prefer ‘computed propierties’ whenever I can, but is there any specific rule that I can use to decide the best moments for ‘watch’ propierties? Thank you.

There isn’t a fixed rule. If you use a watcher, and you notice you simple update the array (for a list view for example), you are better of using computed property

i recently used vue data tables, i had to update the amount entries in the table, i used a watcher (given i need to set an integer on a specific variable). I couldn’t use computed for this.

so i think the rule of thumb is to use computed properties, unless you can’t. Then used watch.

With time, you will gain experience in this, and being able to decide which is best in what you want to do

1 Like

Thank you.
Michele R.

In this example, instead of using:

  watch: {
    specialRequests: function(newRequests, oldRequests) {
      if (newRequests.toLowerCase().includes('meet and greet') || newRequests.toLowerCase().includes('meet-and-greet')) {
       this.ticketType = 'vip';
     }
    }
  }

could you not use

specialRequests: {
      set: function(newRequests) {
        if (newRequests.toLowerCase().includes('meet and greet') || newRequests.toLowerCase().includes('meet-and-greet')) {
          this.ticketType = 'vip';
        }
      }
    }

within computed:?

(I tried it and it didn’t work, but I don’t understand why)