api - How to get data into my Nuxt app for all pages/components
问题描述
I have a file called config-ingest.js
in my plugins directory with the following:
import gql from 'graphql-tag'
export default ({ app }, inject) => {
const client = app.apolloProvider.defaultClient;
const apps = gql`
query {
apps: allApps {
key
tree
}
}
`;
client.query({ query: apps }).then(response => {
inject('configStructure', response.data.apps);
});
}
Although the data is successfully retrieved, it doesn't seem to be available in all my pages and components.
If I want to get data from another server that should be available to all my pages, how would I do this? I want to stick this data in it's own file so I can get the data from any component or page when I please.
解决方案
您应该为此使用 Vuex 商店。 https://nuxtjs.org/guide/vuex-store/
推荐阅读
- python - 使用 Boto3 删除 CloudTrail 以及附加到它的 S3 存储桶
- javascript - 在 react 中改变 chartjs 的设计
- javascript - 反应地图,道具未定义
- discord.js - 我的音乐播放命令不起作用或发送任何错误,我该如何解决这个问题?
- botframework - 超时、图像发送、电子邮件轨道添加到机器人框架作曲家
- ruby-on-rails - Rails 无法在 ActiveAdmin 控制器内创建新对象
- python - Facebook Graph API 错误“请减少您要求的数据量,然后重试您的请求”,即使查询参数中的限制 1 和字段 1
- html - 如何在使用 bootsrap 时更改 css 中的输入文本颜色
- java - Spring:无法解析构造函数的参数名称
- mailkit - 如何将一些自定义参数传递给 Mailkit.smtp 中的 SendCompleted 事件?