【发布时间】:2019-08-30 07:43:54
【问题描述】:
我想更新或重新获取在方法(不是 apollo 对象)中使用的 apollo 查询中的数据。问题是我想在特定事件之后查询和更新该查询,所以我不能在我的代码中直接使用 apollo 对象。
methods: {
async fetchEvents() {
const { data } = await this.$apollo.query({
query: gql`
query(
$someThing: Int,
) {
events (
someThing: $someThing,
) {
total
items {
...
}
}
}
`,
variables() {
return {
...
};
},
});
this.data = data;
},
},
watch: {
'items.view.organizerId': function callback() {
this.fetchEvents();
},
eventsSearchInputVal: function callback() {
this.fetchEvents();
},
'pagination.statusFilter': function callback() {
this.fetchEvents();
},
},
总之,当watch 中的pagination.statusFilter 或eventsSearchInputVal 或items.view.organizerId 发生更改时,应重新获取查询。在这段代码中,当这些变量发生变化时,什么都不会发生。
【问题讨论】:
标签: javascript vue.js graphql apollo vue-apollo