Skip to content

watch有时被触发的问题 #8358

@lclong

Description

@lclong

使用antdesign vue的4.2.6版本,如果在组件TPar.vue中创建侦听器监听任意的响应式变量,比如watVal,如下代码

import { message } from 'ant-design-vue';

watch(watVal, () => {
debugger
console.log('watch侦听器执行了')
});

const info = () => {
message.info('This is a normal message');
};

然后在TPar.vue的按钮点击时销毁TPar.vue组件,发现
如果有message.info('This is a normal message');这一行代码,watch侦听器的回调函数就会被触发;
如果没有message.info('This is a normal message');这一行代码,watch侦听器的回调函数就不会触发。
不止是调用message,测试发现销毁组件,也会触发watch的回调函数。一般来说如果TPar.vue组件被销毁,watch回调函数就不应被触发了吗?

请帮忙看下,谢谢

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions