Tips and guidelines for using the Nuxt Composition API and the Nuxt Apollo module
P粉134288794
2023-08-26 11:07:26
<p>Why can I use the nuxt apollo module with the nuxt composition API? If I try to use this plugin example: </p>
<pre class="brush:php;toolbar:false;">import {Context} from '@nuxt/types'
import {
provide,
onGlobalSetup,
defineNuxtPlugin
} from '@nuxtjs/composition-api'
import {DefaultApolloClient} from '@vue/apollo-composable/dist'
/*** This plugin will connect @nuxt/apollojs and @vue/apollo-composable*/
export default defineNuxtPlugin(({app}: Context): void => {
onGlobalSetup(() => {
provide(DefaultApolloClient, app.apolloProvider?.defaultClient)
})
})</pre>
<p>I got this error: <code>Error: Apollo client with id default not found. Use provideApolloClient() if you are outside of a component setup</code></p>
Install vue/apollo-composable:
npm install --save @vue/apollo-composable
Create nuxt plug-in (provide-apollo-client.ts):