Hello! I am having the same issues trying to fetch data from Nuxt.
After installation and setup I have created two custom types to test.
Nuxt config (nuxt.config.js file):
import { apiEndpoint, token } from './sm.json'
export default {
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://nuxt.com/modules/prismic https://prismic.io/docs/nuxt
'@nuxtjs/prismic',
],
prismic: {
endpoint: apiEndpoint,
apiOptions: {
accessToken: token
},
modern: true
},
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
transpile: ["@prismicio/vue"]
}
}
sm.json file:
{
"apiEndpoint": "https://MY_REPO.prismic.io/api/v2",
"token": "MY_TOKEN",
"libraries": [
"@/slices"
],
"_latest": "0.7.0",
"localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
}
Then I have created a sample page to test API calls (primic.vue):
<template>
<main>
<section>
<button @click="getData">Fetch Data</button>
<h1 v-if="document.data">{{ document.data.title }}</h1>
<PrismicRichText v-if="document.data" :field="document.data.content" />
</section>
</main>
</template>
<script>
export default {
async asyncData({ $prismic, error }) {
// const document = await $prismic.api.getByUID('static_page', 'legal-advise') Not working
const document = await $prismic.api.getSingle('legal-advise') // No results
if (document) {
return { document }
} else {
return {
document: {}
}
}
},
methods: {
async getData() {
const response = await this.$prismic.api.getSingle('legal-advise')
this.document = response || {}
}
}
}
</script>
When I find using the getByUID method the API returns an error:
{
message: "[function at(..)] unexpected field 'my.static_page.uid' on line:1 col:6 in query '[[at(my.static_page.uid, \"legal-advise\")]]'\n[[at(my.static_page.uid, \"legal-advise\")]]\n ^\n"
pos: {line: 1, column: 6, id: 0, location: "query"}
type: "api_parsing_error"
}
And when i use the getSingle method it returns no results:
{
"page": 1,
"results_per_page": 1,
"results_size": 0,
"total_results_size": 0,
"total_pages": 0,
"next_page": null,
"prev_page": null,
"results": [],
"version": "0427058",
"license": "All Rights Reserved"
}
I used the SlideMachine to create the custom types. In this example, the "static_page" is the custom type and "legal_avise" is a document associated to this custom type having UID, title and RichText props.
Mock config for "static_page" custom type:
{
"uid": {
"__TYPE__": "UIDContent",
"value": "pond"
},
"title": {
"__TYPE__": "FieldContent",
"value": "eaten",
"type": "Text"
},
"content": {
"__TYPE__": "StructuredTextContent",
"value": [
{
"type": "paragraph",
"content": {
"text": "Dolor aliquip ea ullamco eu qui occaecat occaecat dolore reprehenderit dolor ea occaecat id ut."
}
}
]
}
}
Prismic.io document:
I also tried to use the API Browser to test queries and fething documents but still having no results.
Versions:
Nuxt: 2.15.8
@nuxtjs/prismic: 1.4.2
@prismicio/slice-simulator-vue: 0.2.2
Can you help me? Thanks a lot!