|
学习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,
};
},
});
|