1

I'm creati an error reporting service, and trying to provide it for the entire app.

import ErrorReporter from "@/services/error_reporter/error-reporter.service";

const app = createApp(App);

app.provide('errorReporter', new ErrorReporter());

and the importing it in a Ts class like so

import {inject} from "vue";

export default class OAuthFedIdService {

    errorReporter: ErrorReporter = inject("errorReporter") as ErrorReporter;

but i get this warning inside the console

inject() can only be used inside setup() or functional components.

is there a way to use the provide/inject functionality of Vue outside of components without getting warnings?

1

1 Answer 1

1

No, there is no way to use the provide/inject outside of components

Just create and export singleton instance of your service. Use inject in components and use direct import anywhere else...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.