请求数据获取成功但是商品页面无法显示
相关代码:
<template> <div class="content"> <div class="category"> <div :class="{'category__item': true, 'category__item--active': currentTab === item.tab}" v-for="item in categories" :key="item.name" @click="() => handleTabClick(item.tab)" > {{item.name}} </div> </div> <div class="product"> <div class="product__item" v-for="item in List" :key="item._id" > <img class="product__item__img" src="http://www.dell-lee.com/imgs/vue3/near.png" alt=""> <div class="product__item__detail"> <h4 class="product__item__title">{{item.name}}</h4> <p class="product__item__sales">月售{{item.sales}}件</p> <p class="product__item__price"> <span class="product__item__yen">¥</span>{{item.price}} <span class="product__item__origin">¥{{item.oldPrice}}</span> </p> </div> <div class="product__number"> <span class="product__number__minus">-</span> 0 <span class="product__number__plus">+</span> </div> </div> </div> </div> </template> <script> import { reactive, ref, toRefs, watchEffect } from 'vue' import { useRoute } from 'vue-router' import { get } from '../../utils/request' const categories = [ { name: '全部商品', tab: 'all' }, { name: '秒杀', tab: 'seckill' }, { name: '新鲜水果', tab: 'fruit' } ] // 和Tab切换相关的逻辑 const useTabEffect = () => { const currentTab = ref(categories[0].tab) const handleTabClick = (tab) => { currentTab.value = tab } return { currentTab, handleTabClick } } const useCurrentListEffect = (currentTab) => { const route = useRoute() const shopId = route.params.id const content = reactive({ list: [] }) const getContentData = async () => { const result = await get(`/api/shop/${shopId}/products`, { tab: currentTab.value }) if (result?.errno === 0 && result?.data?.length) { content.list = result.data } } watchEffect(() => { getContentData() }) const { list } = toRefs(content) return { list } } export default { name: 'jdConent', setup () { const { currentTab, handleTabClick } = useTabEffect() const { list } = useCurrentListEffect(currentTab) console.log(list) return { categories, currentTab, handleTabClick, list } } } </script>
5
收起
正在回答
1回答
同学你好,老师使用源码测试你的代码,报错提示为[Vue warn]: Property "List" was accessed during render but is not defined on instance。根据提示是List书写问题,将List修改为小写的list,则可以正常渲染。如下图:
祝学习愉快!
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星