有没有像 Vue.unuse 这样的东西可以停止使用插件?

2024-01-09

我为 Vue 创建了一个 SignalR 插件:

import AxiosPlugin from "@/plugins/axios";
import { HubConnectionBuilder, LogLevel } from "@aspnet/signalr";
import { PluginObject } from "vue";

export class SignalRPluginOptions {
}

const SignalRPlugin: PluginObject<SignalRPluginOptions> = {
    install(Vue) {
        const connection = new HubConnectionBuilder()
            .withUrl("http://localhost:5100/question-hub")
            .configureLogging(LogLevel.Error)
            .build();

        let startedPromise = null;
        function start() {
            startedPromise = connection.start().catch((err) => {
                return new Promise((resolve, reject) =>
                    setTimeout(() => start().then(resolve).catch(reject), 5000));
            });
            return startedPromise;
        }
        connection.onclose(() => start());

        start();
    },
};

export default SignalRPlugin;

可以与以下产品一起使用:Vue.use(SignalRPlugin);

但是,我想在用户注销时停止使用,但我找不到任何方法/函数Vue为了实现这一点(我已经检查过https://v2.vuejs.org/v2/api/#Vue-use https://v2.vuejs.org/v2/api/#Vue-use).

有解决方法吗?或者我应该使用 Vue 插件以外的其他东西?


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

有没有像 Vue.unuse 这样的东西可以停止使用插件? 的相关文章

随机推荐