Ask Your Question
0

How to observe a class getter in Vue.js?

asked 2023-04-28 15:10:56 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-04-28 15:13:02 +0000

devzero gravatar image

To observe a class getter in Vue.js, you can use a computed property.

For example, if you have a class getter fullName in your Vue component, you can observe it using a computed property like this:

computed: {
  observeFullName() {
    return this.fullName;
  }
},
watch: {
  observeFullName(newVal, oldVal) {
    console.log('Observing fullName:', newVal, oldVal);
  }
}

In this example, observeFullName is a computed property that returns the value of fullName. The watch property then watches this computed property for changes and logs them to the console.

You can replace fullName with any class getter that you want to observe in your Vue component.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-04-28 15:10:56 +0000

Seen: 16 times

Last updated: Apr 28 '23