[英]How to refetch / update result in vue apollo query that used in a method
I want to update or refetch data in apollo query that used in a method (not apollo object). 我想更新或重新获取方法中使用的apollo查询中的数据(不是apollo对象)。 the thing is i wanted to query and update that query after specific event, so i couldn't use apollo object directly in in my code.
事情是我想在特定事件后查询和更新该查询,所以我无法在我的代码中直接使用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();
},
},
in conclusion when pagination.statusFilter
or eventsSearchInputVal
or items.view.organizerId
in watch
got changed the query should refetch. 总之,当
pagination.statusFilter
或eventsSearchInputVal
或items.view.organizerId
在watch
得到了改变查询应重新提取。 in this code nothing happen when those variables get changed. 在这段代码中,当这些变量发生变化时,什
i don't know why but I've changed variables()
method to an object and it got fixed. 我不知道为什么,但我已经将
variables()
方法更改为一个对象并得到修复。 so this code is now working: 所以这段代码现在正在运行:
methods: {
async fetchEvents() {
const { data } = await this.$apollo.query({
query: gql`
query(
$someThing: Int,
) {
events (
someThing: $someThing,
) {
total
items {
...
}
}
}
`,
variables: { // this is an object now
...
},
});
this.data = data;
},
},
watch: {
'items.view.organizerId': function callback() {
this.fetchEvents();
},
eventsSearchInputVal: function callback() {
this.fetchEvents();
},
'pagination.statusFilter': function callback() {
this.fetchEvents();
},
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.