刚刚开始尝试nativescript-vue
。由于它很新,似乎找不到有关 nativescript-vue 与 graphql 集成的良好文档。尝试过vue-apollo
,但无法安装。当我执行 vue add apollo
时,它出错了。有没有关于如何将 nativescript-vue 与 graphql 后端集成或更具体地通过 apollo
集成的好文档?
最佳答案
我想确认nativescript-vue 可以与 vue-apollo 一起正常工作。
您应该首先使用npm或yarn安装apollo-boost
yarn add vue-apollo graphql apollo-boost
main.ts
import Vue from "nativescript-vue";
import routes from "./routes";
import store from "./store";
import * as ApplicationSettings from "tns-core-modules/application-settings";
import VueApollo from "vue-apollo";
import ApolloClient from "apollo-boost";
// GET TOKEN and Prepare for header bearer
const tokenInAppSet = ApplicationSettings.getString("token")
? ApplicationSettings.getString("token").replace(/['"]+/g, "")
: false;
/////////////// APOLLO
export const defaultClient = new ApolloClient({
uri: "http://000.com/graphql",
headers: {
authorization: `Bearer ${tokenInAppSet}`,
}
});
Vue.use(VueApollo);
const apolloProvider = new VueApollo({
defaultClient,
});
new Vue({
store,
apolloProvider,
render: (h) =>
h("frame", [h(tokenInAppSet ? routes.entered : routes.login)]),
}).$start();
如果您想查看某些已安装的版本。
Vue-Apollo 与 Nativescript 示例:
关于Nativescript-vue graphql 后端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56122341/