vue Cannot read properties of undefined (reading 'get')"
时间: 2023-08-28 16:18:33 浏览: 81
vue中渲染对象中属性时显示未定义的解决
5星 · 资源好评率100%
引用中的报错信息"Cannot read properties of undefined (reading '0')"表明在获取goodsInfo.content时遇到了undefined的情况。引用提到可以在展示前加个if判断来避免报错。因此,你可以在模板中加入v-if判断来确保在goodsInfo.content有值之后再进行获取。你可以像下面这样修改你的代码:
```html
<div class="content" v-if="goodsInfo && goodsInfo.content">
<span>{{goodsInfo.content}}</span>
<span>{{goodsInfo.content}}</span>
</div>
```
这样,当goodsInfo和goodsInfo.content都有值时,才会展示content的内容,避免了报错。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [vue报错:Cannot read properties of undefined (reading ‘0‘)](https://blog.csdn.net/Shiny0815/article/details/124635332)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [【vue】前端报错:Cannot read properties of undefined (reading ‘split‘)](https://blog.csdn.net/Triumph_light/article/details/123937699)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文