我第一次尝试使用 Nuxt apollo 5,但它无法正确调用 api,总是返回 null。可能 cors 政策设置不正确。
从来源“http://localhost:3000”获取“https://localhost:5001/api/data”的访问已被 CORS 策略阻止:
<template> {{ data }}</template>
<script setup>
const query = gql`
query ($id: Int!) {
team(id: $id) {
id
name
web
background
teamLogo {
imageUrl
}
}
}
`;
const variables = ref({ id: 41 });
const { data, onError } = await useAsyncQuery(query, {id:41});
我的nuxt配置:
export default defineNuxtConfig({
modules: ['@nuxtjs/apollo', '@nuxtjs/tailwindcss'],
apollo: {
autoImports: true,
authType: 'Bearer',
authHeader: 'Authorization',
tokenStorage: 'cookie',
proxyCookies: true,
clients: {
default: 'https://localhost:5001/api/data'
},
}
})