Vue child component monitors the change of the value passed by the parent component

This is the value to receive from the parent component

    props: {
    
    
      active: {
    
    
        type: [String, Number],
        default: 0,
      }
    },

Use the watchpair activeto monitor the
value change will trigger the handlermethod

    watch: {
    
    
      active: {
    
    
        immediate: true,
        handler(value) {
    
    
          this.isAct = value
        }
      }
    }

vue3

   import {
    
     watchEffect } from "vue";
   setup(props, context) {
    
    
         watchEffect(() => {
    
    
			console.log(props)
		})
     },

Guess you like

Origin blog.csdn.net/AK852369/article/details/112770155