首页 > IT职业 > IT图书 > vuepress中使用vue-apollo
const httpLink = createHttpLink({
// 你需要在这里使用绝对路径
uri,
})
// 缓存实现
const cache = new InMemoryCache()
// 创建 apollo 客户端
const apolloClient = new ApolloClient({
link: httpLink,
cache,
})
const apolloProvider = new VueApollo({
defaultClient: apolloClient,
})
export default ({ Vue, options }) => {
Vue.use(VueApollo)
// xxx
}
此时会提示错误:
"TypeError: Cannot read property ‘defaultClient’ of undefined"
解决方法非常简单
export default ({ Vue, options }) => {
Vue.use(VueApollo)
// 加上下面这行代码
Vue.prototype.$apolloProvider = apolloProvider
// xxx
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3536/viewspace-2826969/ ,如需转载,请注明出处,否则将追究法律责任。