为什么当我在没有传递道具时尝试使用默认标题时道具默认不起作用?

Why props default is not working when I'm trying to use a default title when no props are passed?

我想在没有提供道具时在

标签中显示默认标题“Introduction Props”。但我收到“未捕获(承诺)TypeError:无法读取未定义的属性(读取 'title')”错误。

<p>{{ section.title }}</p>

export default {
  props: {
    section: Object,
    default: {
      type: "section",
      title: "Introduction Props",
      desc: "",
      children: [
        {
          type: "lecture",
          title: "Introduction",
        },
      ],
    }
  },
};

你必须重新安排你的道具:

export default {
  props: {
    section: {
      type: Object,
      default: () => {
        type: "section",
        title: "Introduction Props",
        desc: "",
        children: [
          {
            type: "lecture",
            title: "Introduction",
          }
        ]
      }
    },
};