How to trigger an Apollo GraphQL query on a mounted
event in a Vue.js ponent.
Here is what my code looks like:
<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>
The query runs fine on the first load of the ponent, but how can I get it to run with various events?
How to trigger an Apollo GraphQL query on a mounted
event in a Vue.js ponent.
Here is what my code looks like:
<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>
The query runs fine on the first load of the ponent, but how can I get it to run with various events?
Share Improve this question asked Mar 17, 2017 at 9:16 RaedRaed 6981 gold badge7 silver badges24 bronze badges 1- Make the query a method and call it when the events occur. – Bert Commented Mar 17, 2017 at 14:17
1 Answer
Reset to default 6this.$apollo.queries.books.refetch();
if you have variables and need to update them on each call, pass them as parameter of the method refetch:
this.$apollo.queries.books.refetch(variables);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745573780a4633839.html
评论列表(0条)