Vue Composition Api Watch Props

Posted on  by admin

Modified1 month ago. How can I call a function when a prop is updated?

parent container:. child container:. this code gets an error: Invalid watch source..How can I listen for an update of tthe props?

Watch API with ref

Hope someone can help me out!! 134134 bronze badges. Try to return the prop from function as first parameter :.

Instead of watch(props.type, do watch(()=>props.type, because ()=>props.type is an arrow function that return the prop and it's the parameter of the watcher property.

1414 gold badges107107 silver badges134134 bronze badges. 134134 bronze badges. You have two possible solutions:.

Your can make a computed property and watch it. You can use arrow function like this. Mohamed EL BAHJAMohamed EL BAHJA. The watch API is part of the larger Vue Composition APIs.

Introduction to the Watch API

It takes a data source and a callback function that executes when the provided data changes.

Watch API with Reactive

  • How to watch for local storage changes in Vue.js?

    Sometimes, we want to watch for local storage changes in Vue.js. In this article, we'll…

  • Watch Input Change with Vue.js

    We can watch for input value changes with Vue.js with the watch property. Add a…

  • Listen for Prop Changes in a Vue Component

    We can listen for prop changes by using the watch property. For instance, we can…