P粉3995850242023-08-27 00:00:55
安装 vue/apollo-composable:
npm install --save @vue/apollo-composable
创建 nuxt 插件(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) }) })