Is there something like Vue.unuse to stop using a plugin?

坚强是说给别人听的谎言 提交于 2021-02-05 11:56:02

问题


I created a SignalR plugin for Vue:

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;

which is fine to be used with: Vue.use(SignalRPlugin);

However, I would like to stop using when my user is logging out, but I can't find any method / function on Vue to achieve that (I already checked https://vuejs.org/v2/api/#Vue-use).

Is there a workaround? Or should I use something different other than a Vue plugin?

来源:https://stackoverflow.com/questions/57415676/is-there-something-like-vue-unuse-to-stop-using-a-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!