Vue-Apollo-无法访问查询结果

时间:2018-09-06 19:08:09

标签: vue.js apollo graphql-js apollo-client vue-apollo

我无法访问我的阿波罗查询的结果对象。我想使用结果将其显示在plot.ly图中。

const apolloClient = new Apollo.lib.ApolloClient({
  networkInterface: Apollo.lib.createNetworkInterface({
    uri: '{% url 'graphql' %}',
    transportBatching: true,
  }),
  connectToDevTools: true,
})

const apolloProvider = new VueApollo.ApolloProvider({
  defaultClient: apolloClient,
})

const VALUE_QUERY = Apollo.gql`
query {
  allSensordata {
    id
    value
  }
}
`

这只是与plot.ly一起使用的Vue组件。

//VueJS Component
Vue.component("reactive-chart", {
  props: ["chart"],
  template: '<div :ref="chart.uuid" style="width:600px;height:250px;"></div>',
  mounted() {
    Plotly.plot(this.$refs[this.chart.uuid], this.chart.traces, this.chart.layout);
  },
  watch: {
    chart: {
      handler: function() {
        Plotly.react(
          this.$refs[this.chart.uuid],
          this.chart.traces,
          this.chart.layout
        );
      },
      deep: true
    }
  }
});

这里是Vue主要代码,我想将阿波罗graphql结果带到图中。

//VueJS Main App
var app = new Vue({
  delimiters: ['[[', ']]'],
  el: "#app",
  // Apollo GraphQL
  apolloProvider,
  apollo: {
    allSensordata: {
      query: VALUE_QUERY,
      loadingKey:'loading',
    },
  },
  data() {
    return {
      loading: 0,
      chart: {
        uuid: "123",
        traces: [
          {
            y: [1,2,3,4,3,2,1], //Here should be: this.allSensordata.value
            line: {
              color: "#5e9e7e",
              width: 4,
              shape: "line"
            }
          }
        ],
        layout: {}
      }
    };
  },
});

我认为我没有得到Apollo模块的对象结构。感谢您的帮助!

0 个答案:

没有答案