问题
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