Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
838 views
in Technique[技术] by (71.8m points)

nuxt.js - Get all tags from document type

I'm having a Nuxt project where I use Prismic as CMS.

I need to get all tags from document type.

I tried with this query but I get all the tags from the API, including tags I dont need.

async fetch() { this.filters = await this.$prismic.api.tags }

In documentation they also provide example query to get documents by tags.

How can I write a query to receive the tags only who can be found in given document type.

question from:https://stackoverflow.com/questions/66067968/get-all-tags-from-document-type

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have answered this already on our forum, but the only way to get the tags for a given custom type would be to query all documents of that type: https://prismic.io/docs/technologies/query-content-from-cms-nuxtjs#query-all-documents-of-a-type 1

Then you would need to iterate through the documents and add the tags to and array.

Normally if your doing an extra query like this you might be worried about performance, but given Nuxt.js's static deployment capabilities this shouldn't be an issue.

A good idea for this might be to do the query for these tags in the vuex store so that the query is done once as is available globally.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...