Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
840 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...