vue组件传值异常,页面正常渲染,浏览器控制台报错 Expected Object, got Function;Expected String, got Function等异常
异常信息:[Vue warn]: Invalid prop: type check failed for prop "tableData". Expected Object, got Function.found in子组件中定义:name: "totalList",props: {width: {type: String,default: "10...
·
异常信息:
[Vue warn]: Invalid prop: type check failed for prop "tableData". Expected Object, got Function.
found in
子组件中定义:
name: "totalList", props: { width: { type: String, default: "100%" }, height: { type: String, default: "300px" }, tableData:Object }
父组件中用法:
<total-list :tableData="totalData"></total-list>
data() { return { totalData:Object } }
问题原因:
由于vue是基于动态绑定的,子组件在totalData未被赋值前渲染,子组件无法获取到实际的值而是Object对象,String对象,导致渲染时发生异常,
解决办法:
就是将需要传递给子组件的的参数,赋予初始值,而不能只指定类型,比如String类型要赋予“”,Object赋予{},然后传递给子组件
修改后的父组件:
<total-list :tableData="totalDeatailTableData"></total-list>
data() { return { totalData:{} } }
更多推荐
已为社区贡献1条内容
所有评论(0)