【发布时间】:2020-10-30 22:50:19
【问题描述】:
我们正在尝试向 Quasar Framwework 添加一个引导文件,以便能够将 @vue/apollo-composable 与 Vue 组合 API 一起使用。 This tutorial 解释了旧版 apollo 客户端是如何完成的,this one 解释了新版本是如何完成的。
我们遇到的问题是将 Apollo 客户端连接到 Vue。所以我们需要把example from the docs翻译成Quasar启动文件:
// example docs
import { provide } from '@vue/composition-api'
import { DefaultApolloClient } from '@vue/apollo-composable'
const app = new Vue({
setup () {
provide(DefaultApolloClient, apolloClient)
},
render: h => h(App),
})
Quasar 启动文件:
import { createHttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { ApolloClient } from 'apollo-client'
import { DefaultApolloClient } from '@vue/apollo-composable'
import { provide } from '@vue/composition-api'
const httpLink = createHttpLink({
uri: 'http://localhost:4000/graphql',
})
const cache = new InMemoryCache()
const apolloClient = new ApolloClient({
link: httpLink,
cache
});
export default async ({ app } /* { app, router, Vue ... } */) => {
app.setup(provide(DefaultApolloClient, apolloClient))
}
问题:
在 Quasar Framework 启动文件中添加 Apollo 客户端的正确语法是什么?
【问题讨论】:
标签: javascript vue.js apollo apollo-client quasar-framework