uni-app 使用HTML绑定接口数据报undefined

语法:

<view class="indexADleft">
	<image :src="imgUrl+content[0].image" mode=""></image>
</view>
<script>
	export default {
    
    
		props:['content']
	}
</script>

错误如下:
在这里插入图片描述
错误原因:此处 content 默认为 undefined,页面开始渲染时 content 为空
解决办法:使用template 标签包裹元素,并使用 v-if 判断数据是否为空 (使用template 是因为 dom 结构不存在 template 标签)

<view class="indexADleft">
	<template v-if="content.length>0">
		<image :src="imgUrl+content[0].image" mode=""></image>
	</template>
</view>

猜你喜欢

转载自blog.csdn.net/weixin_44640323/article/details/112394366
今日推荐