Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

vue通过props传递对象会报错

父组件App.vue
图片描述

子组件sonCp.vue
图片描述

数据结构
图片描述

报错但是数据能渲染上去
图片描述

求解,顺便帮我看一下我取数据方式对么,是放到created这个里面么


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

子组件最初得到的是空字符串,木有.acount.name之类的属性,所以出错。

最简单的解决办法:

父组件App.vue中的

<sonCp :dataObj="dataObj" />

改成:

<sonCp :dataObj="dataObj" v-if="dataObj" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...