我是新手,不知何故我没有运气调用我的本地主机 api。
Nuxt.config.ts
export default defineNuxtConfig({
modules: ['@nuxtjs/apollo'],
apollo: {
clients: {
default: {
httpEndpoint: 'https://main--spacex-l4uc6p.apollographos.net/graphql'
},
other: {
httpEndpoint: 'https://localhost:5001/api/data'
},
},
},
})
App.vue:ship api 运行良好,我的 localhost api 运行不正常,尽管它在 postman 测试中运行良好。请帮忙指出我做错了什么?
<template>
<div>
<p>There are {{ data?.ships?.length || 0 }} ships.</p>
<p>team {{ data2 }}</p>
</div>
</template>
<script lang="ts" setup>
const query = gql`
query getShips($limit: Int!) {
ships(limit: $limit) {
id
name
}
}
`;
const { data } = await useAsyncQuery(query, { limit: 5 }); // works
const query2 = gql`
query getTeam($id: Int!) {
team(id: $id) {
id
name
}
}
`;
const { data2 } = await useAsyncQuery(query2, { id: 41 }, "other"); // fails
</script>