P粉3995850242023-08-27 00:00:55
Install vue/apollo-composable:
npm install --save @vue/apollo-composable
Create nuxt plug-in (provide-apollo-client.ts):
import { Context } from '@nuxt/types' import { onGlobalSetup, defineNuxtPlugin } from '@nuxtjs/composition-api' // @ts-ignore import { provideApolloClient } from '@vue/apollo-composable' /** * This plugin will connect @nuxt/apollojs with @vue/apollo-composable */ export default defineNuxtPlugin(({ app }: Context): void => { onGlobalSetup(() => { provideApolloClient(app.apolloProvider?.defaultClient) }) })