子组件监听父组件传入的值:

const props = defineProps({
  contentId: {
    type: String || Number, 
    required: true,
  },
});

// 整体监听
watch(props,(newValue, oldValue)=>{
  // 
})

// 监听contentId
watch(()=>props.contentId,(newValue, oldValue)=>{
  // 
},{ deep: true, immediate:true})

// 还可以使用watchEffect监听
watchEffect(()=>{
    let id=props.contentId
   //
})

Logo

前往低代码交流专区

更多推荐