[英]How to use Graphql Vue Apollo on older IOS / older browser?
I just realize and noticing that my vue app doesn't work well on some older browsers (ios 9 for example). 我只是意识到并注意到我的vue应用程序在某些旧版浏览器上运行不正常(例如ios 9)。 I used the vue-apollo to get data from graphql api using django graphene , but it doesn't event get called on the first load when i debug it. 我使用vue-apollo使用django graphene从graphql api获取数据,但是当我调试它时,它不会在第一次加载时调用事件。
Previously i get error like "fetch is not found globally", but then i already fix it by adding "unfetch" to the ApolloClient config. 以前我得到的错误如“全局未找到fetch”,但之后我已经通过在ApolloClient配置中添加“unfetch”来修复它。 But i still can't see on xhr network the api get called. 但我仍然无法在xhr网络上看到api被调用。 I haven't try with isomorphic-fetch 我没有尝试过isomorphic-fetch
Here's my code for the apollo client config: 这是我的apollo客户端配置代码:
// src/utils/graphql.js
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
import fetch from 'unfetch'
export default new ApolloClient({
// Provide the URL to the API server.
link: new HttpLink({ uri: '/api/', fetch: fetch }),
// Using a cache for blazingly
// fast subsequent queries.
cache: new InMemoryCache(),
connectToDevTools: true
});
and i specify it like so in the main.js 我在main.js中这样指定它
import apolloClient from '../utils/graphql'
import VueApollo from 'vue-apollo'
Vue.use(VueApollo);
Vue.config.silent = true
const apolloProvider = new VueApollo({
defaultClient: apolloClient,
defaultOptions: {
$loadingKey: "loading"
}
})
This is example of the apollo that i use inside the main.js as well using the smart query: 这是我在main.js中使用的apollo示例以及使用智能查询:
apollo: {
currentUser: {
query: GET_LOGGED_USER,
skipQuery() {
return this.skipUser
}
}
}
How can i make it work on ios 9 / any older browser? 我怎样才能在ios 9 /任何旧浏览器上运行它?
Ok, after debugging it for two days, I finally found out the issue. 好的,经过两天的调试后,我终于找到了问题。 So it turns out that i need to add and configure babel/polyfill as well in order to make it works, and add it to the entry point of my app. 所以事实证明我需要添加和配置babel / polyfill以使其工作,并将其添加到我的应用程序的入口点。
Hope everyone who has the same issue can learn from my mistake lol 希望每个有同样问题的人都能从我的错误中吸取教训
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.