Javascript 如何在方法中使用的vue apollo查询中重新蚀刻/更新结果
我想更新或重新提取apollo查询中用于方法(而不是apollo对象)的数据。问题是我想在特定事件之后查询并更新该查询,所以我不能在代码中直接使用apollo对象Javascript 如何在方法中使用的vue apollo查询中重新蚀刻/更新结果,javascript,vue.js,graphql,apollo,vue-apollo,Javascript,Vue.js,Graphql,Apollo,Vue Apollo,我想更新或重新提取apollo查询中用于方法(而不是apollo对象)的数据。问题是我想在特定事件之后查询并更新该查询,所以我不能在代码中直接使用apollo对象 methods: { async fetchEvents() { const { data } = await this.$apollo.query({ query: gql` query( $someThing: Int,
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();
},
},
总之,当
pagination.statusFilter
或eventsSearchInputVal
或项中的查看.organizerId
发生更改时,应重新调用查询。在这段代码中,当这些变量被更改时,什么也不会发生。我不知道为什么,但我已经将variables()
方法更改为一个对象,它得到了修复。
因此,该代码现在正在运行:
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();
},
},