学习vue3.0记录下props监听:
第一种直接监听这个props

export default defineComponent({
  props: {
    isOpen: Boolean,
  },
  emits: {
    "close-modal": null,
  },
  setup(props, context) {
    watch(
      props,
      (newProps) => {
        console.log(newProps.isOpen); //这里看到新值
      }
    );
    const closeModal = () => {
      context.emit("close-modal");
    };
    return {
      closeModal,
    };
  },
});

第二种监听里边的某一个属性

export default defineComponent({
  props: {
    isOpen: Boolean,
  },
  emits: {
    "close-modal": null,
  },
  setup(props, context) {
    watch(
      () => props.isOpen,
      (newProps) => {
        console.log(newProps);//查看新值
      }
    );
    const closeModal = () => {
      context.emit("close-modal");
    };
    return {
      closeModal,
    };
  },
});
Logo

前往低代码交流专区

更多推荐