question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support @vue/composition-api setup function

See original GitHub issue

What problem does this feature solve?

Don’t extend context and this with $axios field

What does the proposed changes look like?

import { useAxios } from '@nuxtjs/axios';

...
setup() {
  const $axios = useAxios();

  return { $axios };
}
...
<div align="right">This feature request is available on Nuxt community (#c365)</div>

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
NickBollescommented, Aug 30, 2020

Here’s a simple plugin composable you can create. The same method can be used for almost all nuxt modules

import { useContext } from "@nuxtjs/composition-api";
import { NuxtAxiosInstance } from "@nuxtjs/axios";

export function useAxios(): NuxtAxiosInstance {
  const { $axios } = useContext();

  if (!$axios) {
    // throw error, no store provided
    throw new Error("nuxt axios is not defined!");
  }
  return $axios;
}
2reactions
danielroecommented, Aug 26, 2020

@crutch12 If you want to use the provide/inject methodology with Nuxt 2 you can do so with the onGlobalSetup helper.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Composition API: setup() - Vue.js
The setup() hook serves as the entry point for Composition API usage in components in the following cases:
Read more >
Vue.js 3 Composition API: the SetUp Function | Geek Culture
Vue 3 introduced the setUp function. It enables us to extract repeatable parts of components into reusable pieces of code.
Read more >
An ultimate guide to the Vue 3 Composition API
Setup function. The setup() function enables you to extract parts of components and group them logically together. It helps you wrap your logic ......
Read more >
Vue 3.2 - Using Composition API with Script Setup
Vue 3 introduced the Composition API as a new way to work with reactive state in a Vue application. Rather than organizing code...
Read more >
Diving Into Vue 3 - The Setup Function - Deepgram Blog ⚡️
The Composition API is born from experience - the experience of struggling to keep track of logic jumping around within a Vue component,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found