如何在DRF上的NUXT.JS中获取数据

编程入门 行业动态 更新时间:2024-10-28 04:15:26
本文介绍了如何在DRF上的NUXT.JS中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试了NUXT,并尝试遵循他网站上的手册.但是现在我陷入了从DJANGO提取数据的问题.

I tried NUXT and tried following the manual on his website. But now I'm stuck with the problem of fetching data from DJANGO.

这是我的代码.

<template> <div> <ul v-for="product in products" :key="product.results.id"> <NuxtLink :to="`/${product.results.id}`"> <li>{{ product.results.id }}</li> </NuxtLink> </ul> </div> </template> <script> export default { async asyncData() { const products = await fetch( '***/product_api/api/v1/Product/?format=json' ).then((res) => res.json()) // .then(productmap => console.log(productmap.results[0].name)) return { products } } } </script>

和我的JSON

{ "count": 46786, "next": "***/product_api/api/v1/Product/?limit=100&offset=100", "previous": null, "results": [ { "id": 2, "catID": "TOO08", "catname": "เครื่องมือช่าง", "sku": "1690", "name": "เส้นเอ็น SL NO.50", "brand": "ระกา", "price": "40", "detail": "เส้นเอ็น SL NO.50", "imgurl1": "****", "imgurl2": "****", "productclick": "*****" },

我尝试按照基本指南进行操作.但是还是不明白有人能解决这个问题吗?

I tried following the guide to the basics. But still don't understand Anyone have a way to solve this problem?

我只想创建动态页面.nuxtjs/examples/routing-dynamic-pages

I just want to do Dynamic Pages.nuxtjs/examples/routing-dynamic-pages

推荐答案

您应该遍历 products.results 数组

<template> <div> <ul v-for="product in products.results" :key="product.id"> <NuxtLink :to="`/${product.id}`"> <li>{{ product.id }}</li> </NuxtLink> </ul> </div> </template>

更多推荐

如何在DRF上的NUXT.JS中获取数据

本文发布于:2023-07-16 04:22:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117782.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   如何在   NUXT   DRF   JS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!