gpt4 book ai didi

vue.js - 如何为 Vue Apollo 导入 Apollo Client 3?

转载 作者:行者123 更新时间:2023-12-03 06:45:08 37 4
gpt4 key购买 nike

Vue-Apollo 3.04 的发行说明指出现在支持 Apollo Client 3。由于 Apollo Client 3 的文档声明 ApolloClientInMemoryCacheHttpLink 现在都在一个 中@apollo/client 包 - 不像以前的单个包。

https://github.com/vuejs/vue-apollo/releases/tag/v3.0.4

https://www.apollographql.com/docs/react/migrating/apollo-client-3-migration/

但是 Vue-Apollo 的文档没有变化(apollo-client -> @apollo/client ?)关于如何应用新的更改。此外,Apollo Client 3 文档指出,对于 Vue,您必须从 @apollo/client/core< 导入 ApolloClient/

所以我尝试了自己的方式,但我的导入似乎失败了。我从 npmm run serve 收到了这些错误消息。似乎他想导入一些 react 东西。

     ERROR  Failed to compile with 8 errors                                                                                                             20:25:20
This dependency was not found:

* react in ./node_modules/@apollo/client/react/context/ApolloConsumer.js, ./node_modules/@apollo/client/react/context/ApolloContext.js and 6 others

To install it, you can run: npm install --save react

vue-apollo.js (from old project that worked)


import Vue from 'vue'
import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import VueApollo from 'vue-apollo'

vue-apollo.js (with new apollo client 3)


import Vue from 'vue'
import { ApolloClient } from '@apollo/client/core'
import { InMemoryCache } from '@apollo/client/cache'
import { HttpLink } from '@apollo/client'
import VueApollo from 'vue-apollo'

package.json

     "dependencies": {
"@apollo/client": "^3.1.3",
"core-js": "^3.6.5",
"graphql": "^15.3.0",
"js-cookie": "^2.2.1",
"subscriptions-transport-ws": "^0.9.18",
"vue": "^2.6.11",
"vue-apollo": "^3.0.4"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"vue-template-compiler": "^2.6.11",
"webpack-bundle-tracker": "^1.0.0-alpha.1"
},

Question

如何使用 vue apollo 正确导入新的 apollo client 3

最佳答案

好吧,休息后我尝试了这个并且成功了。

vue-apollo.js


import Vue from 'vue'
import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client/core';
import VueApollo from 'vue-apollo'

现在编译器找到了一切。虽然在 Apollo Client 3 文档中我只能找到一个关于新的 Client 3 和 Vue 的引用,但似乎所有 react 的东西都来自 @apollo/client 而 Vue 和其他来自 @apollo/client/core

关于vue.js - 如何为 Vue Apollo 导入 Apollo Client 3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63457684/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com