Watch Props in Vue/Nuxt Composition API

itsmnthn

Manthankumar Satani

Posted on May 15, 2022

Watch Props in Vue/Nuxt Composition API

Watch dynamic props inside setup method in Nuxt3 or Vue3 CompositionAPI

<script lang="ts" setup>
import { defineProps, watch } from 'vue'

const prop = defineProps({
  value: { default: '', type: [String, Number] },
})

watch(
  () => prop.value,
  () => {
    console.log('prop value changed', prop.value)
  }
)
</script>

<template>
  <div>{{ value }}</div>
</template>

Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
itsmnthn
Manthankumar Satani

Posted on May 15, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related