二话不说上代码
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);
});