Nativescript-vue graphql 后端?

标签 nativescript nativescript-vue

刚刚开始尝试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 示例:

https://github.com/kaanguru/apollo-jwt

https://github.com/kaanguru/simple-question

关于Nativescript-vue graphql 后端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56122341/

相关文章:

nativescript-vue - 如何隐藏 suggestionView 而不必使用 Nativescript Vue js 删除 RadAutoCompleteTextView 中的字符

ios - headless 网页 View

nativescript - 将填充的 couchbase lite 数据库保存为 Nativescript 和 vue 中的备份?

android - 如何在 Android 上使用 NativeScript 和 Angular 更改 StatusBar 颜色或将其设置为透明?

vue.js - NativeScript-Vue 中的音频播放器

nativescript - 根据设备高度动态调整 ScrollView 中 Nativescript ContentView 的大小

android-actionbar - 如何更改 Nativescript 中的 NavigationButton 和 ActionBar 标题之间的距离?

css - 如何使用 NativeScript GridLayout 创建 2 x 2 网格

javascript - 奇怪的javascript变量转储

javascript - Nativescript Javascript 和 Watson Cloud SDK 集成