在 Vue3 组合中 API 让观察者立即工作
In Vue3 composition API make the watcher work immediately
使用 Vue3 组合 API。我如何让 watched 立即工作。以下代码无效。
watch((immediate=true) => props.isOpen, () => {
if (props.isOpen && props.preventBackgroundScrolling) {
document.body.style.setProperty('overflow', 'hidden')
} else {
document.body.style.removeProperty('overflow')
}
});
它应该作为选项放置:
watch(() => props.isOpen, () => {
if (props.isOpen && props.preventBackgroundScrolling) {
document.body.style.setProperty('overflow', 'hidden')
} else {
document.body.style.removeProperty('overflow')
}
},{immediate:true});
或
watch('props.isOpen', () => {
if (props.isOpen && props.preventBackgroundScrolling) {
document.body.style.setProperty('overflow', 'hidden')
} else {
document.body.style.removeProperty('overflow')
}
},
{immediate:true}
);
使用 Vue3 组合 API。我如何让 watched 立即工作。以下代码无效。
watch((immediate=true) => props.isOpen, () => {
if (props.isOpen && props.preventBackgroundScrolling) {
document.body.style.setProperty('overflow', 'hidden')
} else {
document.body.style.removeProperty('overflow')
}
});
它应该作为选项放置:
watch(() => props.isOpen, () => {
if (props.isOpen && props.preventBackgroundScrolling) {
document.body.style.setProperty('overflow', 'hidden')
} else {
document.body.style.removeProperty('overflow')
}
},{immediate:true});
或
watch('props.isOpen', () => {
if (props.isOpen && props.preventBackgroundScrolling) {
document.body.style.setProperty('overflow', 'hidden')
} else {
document.body.style.removeProperty('overflow')
}
},
{immediate:true}
);