Skip to content

Vue3 watch props 监听属性变化

Published: at 10:15 AMSuggest Changes

二话不说上代码

import { watch, toRefs } from "vue";
const props = defineProps({
  visible: {
    type: Boolean,
    default: () => {
      return false;
    },
  },
});
const visible = toRefs(props).visible;
watch(visible, (newValue, oldValue) => {
  alert(newValue);
});

参考文章


Previous Post
Vue3 父子组件传值及方法调用
Next Post
JS 点击事件监听失效问题及解决