3

I like to know if there is a way to access in a plugin the context variables? Which other variables / objects exists apart from the "process" object? Unfortunately I could not found a clear description nor a reference about the "process" object at the nuxt side

i.e. plugins/helper.js

const myHelper = {
  helpFunction(arg) {
    if (process.server) {
      ...
    }
    return ...;
  },

1 Answer 1

4

If you export a function in your plugin, you will automatically have access to nuxt context as it's first argument (docs):

    export default (context, inject) => {
      context.app.helpFunction= (arg) => {
          if (process.server) {
             ...
          }
          return ...;
      }
    }

now you can use your helper function in any component like this:

    this.$helpFunction(someArgs)...
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.