刚刚开始尝试使用nativescript-vue。由于它很新,似乎找不到关于nativescript-vue与graphql集成的好文档。已尝试vue-apollo,但无法安装。当我执行vue add apollo时,它会出错。有没有关于如何将nativescript-vue与graphql后端集成,或者更具体地说是通过apollo集成的好文档
发布于 2020-05-03 18:11:44
我想确认nativescript-vue与vue-apollo一起工作正常。
您应该首先使用npm或yarn安装apollo-boost
yarn add vue-apollo graphql apollo-boostmain.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 with Nativescript示例:
https://stackoverflow.com/questions/56122341
复制相似问题