各位大神好,我是一名uni-app的新手,最近刚开始研究uni-app,然后遇到了一个奇怪的问题,还请大神们帮忙看一下是什么原因,也有可能是我太菜了。
我想调用json数据中的产品图片,在json数据中有显示对应的产品图片数据,但是我调用的时候一直报错:Error in render: "TypeError: Cannot read property 'product_img_small' of undefined,json中的其他数据都可正常调用
这是我的代码:
<view class="products">
<view class="product" v-for="(product, key) in category.product" :key="key"
@tap="showProductDetailModal(product)">
<image :src="product.images[0].product_img_small" mode="widthFix" class="image"></image>
<view class="content">
<view class="name">{{ product.product_name }}</view>
<view class="labels">
<view class="label"
:style="{color: label.label_color, background: $util.hexToRgba(label.label_color, 0.2)}"
v-for="label in product.labels" :key="label.id">{{ label.name }}</view>
</view>
<view class="description">{{ product.introduction }}</view>
<view class="price">
<view>€ {{ product.price }}</view>
<actions :materials-btn="!product.is_single"
@materials="showProductDetailModal(product)"
:number="productCartNum(product.id)"
@add="handleAddToCart(product)"
@minus="handleMinusFromCart(product)" />
</view>
</view>
</view>
</view>
async onLoad() {
var that = this;
this.$http.get('categories',{include: 'product,product.images,product.allergies,product.attributes'}).
then(function (response) {
//这里只会在接口是成功状态返回
that.categories = response.data;
}).catch(function (error) {
//这里只会在接口是失败状态返回,不需要去处理错误提示
console.log(error);
});
},