admin管理员组文章数量:1026989
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);
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);
本文标签: javascriptHow to trigger an Apollo query in a Vue component eventStack Overflow
版权声明:本文标题:javascript - How to trigger an Apollo query in a Vue component event? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745573778a2156894.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论