ITPub博客

首页 > IT职业 > IT图书 > vuepress中使用vue-apollo

vuepress中使用vue-apollo

IT图书 作者:socall 时间:2021-09-09 10:52:42 0 删除 编辑

直接上代码:

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/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-30

  • 博文量
    80
  • 访问量
    556