Anj*_*i.S 7 vue.js graphql apollo-client
我想从 中获取数据GraphQL,我尝试过使用静态参数并且它有效。但是当我尝试使用 时QueryParams,它在我的网络上返回了错误 404。
我希望我的 GraphQL 查询成为动态参数。谁能给我关于QueryParams在 Apollo Vue 中使用GraphQL 的解决方案?
data(){
return{
idLabel:3
}
},
//my file .gql
query post($idLabel:Int!){
post(id: $idLabel) {
id
title
body
comments(options:{paginate:{page:1 limit:10}}){
data{
id
name
email
}
}
}
}Run Code Online (Sandbox Code Playgroud)
<ApolloQuery
:query="require('./graphql/PostGraphqlzero.gql')"
:variables="{ idLabel }"
>
<template v-slot="{ result: { loading, error, data } }">
<!-- Loading -->
<div v-if="loading" class="loading apollo">Loading...</div>
<!-- Error -->
<div v-else-if="error" class="error apollo">An error occurred</div>
<!-- Result -->
<div v-else-if="data" class="result apollo">
<div v-for="(todo) in data" :key="todo.id">
<div class="alert alert-primary" role="alert"> {{todo.title}}</div>
<div v-for="(todos) in todo.comments.data" :key="todos.id">
{{todos.name}}
</div>
</div>
</div>
<!-- No result -->
<div v-else class="no-result apollo">No result :(</div>
</template>
<!-- TODO -->
</ApolloQuery>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
36 次 |
| 最近记录: |