如何在 Vue 组件事件中触发 Apollo 查询?
How to trigger an Apollo query in a Vue component event?
如何在 Vue.js 组件中的 mounted
事件上触发 Apollo GraphQL 查询。
我的代码如下所示:
<template>
</template>
<script>
import gql from 'graphql-tag';
const myQuery = gql`
query someQuery {
books{
id
}
}`
export default {
data: () => ({
books: []
}),
apollo: {
books: {
query: myQuery,
},
},
mounted () {
// run the appollo query here as well ?
}
};
</script>
第一次加载组件时查询 运行 没问题,但我怎样才能通过各种事件将其发送到 运行?
this.$apollo.queries.books.refetch();
如果您有变量并且需要在每次调用时更新它们,请将它们作为方法 refetch 的参数传递:
this.$apollo.queries.books.refetch(variables);
如何在 Vue.js 组件中的 mounted
事件上触发 Apollo GraphQL 查询。
我的代码如下所示:
<template>
</template>
<script>
import gql from 'graphql-tag';
const myQuery = gql`
query someQuery {
books{
id
}
}`
export default {
data: () => ({
books: []
}),
apollo: {
books: {
query: myQuery,
},
},
mounted () {
// run the appollo query here as well ?
}
};
</script>
第一次加载组件时查询 运行 没问题,但我怎样才能通过各种事件将其发送到 运行?
this.$apollo.queries.books.refetch();
如果您有变量并且需要在每次调用时更新它们,请将它们作为方法 refetch 的参数传递:
this.$apollo.queries.books.refetch(variables);