Vue3.0监听props方法
学习vue3.0记录下props监听:第一种直接监听这个propsexport default defineComponent({props: {isOpen: Boolean,},emits: {"close-modal": null,},setup(props, context) {watch(props,(newProps) => {console.log(newProps.isOpe
·
学习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,
};
},
});
更多推荐
已为社区贡献1条内容
所有评论(0)