问题
今天遇到个小坑,就是 vue 里使用 props 传参类型为 Object 的时候设置
<template>
<div class="pre-archive-info">
<template v-if="infoData.kaimo !== null">{{ infoData.kaimo }}</template>
</div>
</template>
<script>
export default {
name: "PreArchiveInfo",
props: {
infoData: {
type: Object,
default: () => {}
}
}
};
</script>

组件里添加下面代码:
infoData:{{ infoData }} type:{{ typeof infoData }}
发现 infoData 是 undefined

解决
之前我的写法如下,这种是可以的。
<script>
export default {
name: "PreArchiveInfo",
props: {
infoData: {
type: Object,
default: () => {
return {};
}
}
}
};
</script>
下面我们可以尝试问问 chatgpt 看看怎么说:

我试了一下
<script>
export default {
name: "PreArchiveInfo",
props: {
infoData: {
type: Object,
default: () => ({})
}
}
};
</script>
