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
814 views
in Technique[技术] by (71.8m points)

nuxt.js - Prismic Query - Query by Category

I have this product structure:

enter image description here

And I would like to query by the uid of toys. However, this query is not working:

const products = await this.$prismic.api.query([
  this.$prismic.predicates.at('my.product.category','toys'
)]

It doesn't work unfortunately.

question from:https://stackoverflow.com/questions/65660479/prismic-query-query-by-category

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

1 Reply

0 votes
by (71.8m points)

Fairly new to Prismic so this took me a while to figure out. The method is very straightforward:

Once you make a relationship between two types (ie, products and categories), you can use this query to get products by a specific category:

const products = await this.$prismic.api.query(
   this.$prismic.predicates.at('my.product.category', 'category_id')
)

The category id is found in the category document (it looks something like: X_uidsfsdFKHF2). Per the documentation, that is the ONLY way to make this query work. You can't use uid or type.

enter image description here


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

...