刚刚开始尝试nativescript-vue
。由于它很新,因此似乎找不到关于与graphql进行nativescript-vue集成的良好文档。尝试过vue-apollo
,但无法安装。当我执行vue add apollo
时,它会出错。有没有关于如何将nativescript-vue与graphql后端或更具体地通过apollo
集成的好文档?
答案 0 :(得分:2)
我想确认 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();
如果要查看某些已安装的版本。
带有Nativescript示例的Vue-Apollo: