是否可以控制已经渲染的Vue实例,销毁所有的watch事件 #7353
Unanswered
enjoy-wind
asked this question in
Help/Questions
Replies: 1 comment 2 replies
-
方案一: 使用watchEffect定义监听事件,然后再把stop暴露给外部,或者watch一个全局状态判断执行stop const stop = watchEffect(() => {})
// 这种方法你就需要ref去把每个组件的stop执行一次
defineExpose({
stop
})
// 利用状态管理去控制组件内部执行stop
const store = useStore()
const freeze = computed(() => store.common.freeze)
watch(()=>freeze , (val)=>{
val && stop()
}) 方案二:watch中间根据全局状态判断是否要执行请求 const store = useStore()
const freeze = computed(() => store.common.freeze)
watch(()=>xx, ()=>{
if(freeze.value){
return
}
// 请求
}) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
背景:
产品希望一个组件保留页面的内容,仅仅屏蔽页面的接口请求。
我在全局钩子函数beforeCreate统一关闭了请求,但是对于组件里面的watch调用接口,我无法做到,是否有一个方案是我在渲染完所有组件后,销毁改组件的所有实例
Beta Was this translation helpful? Give feedback.
All reactions