在 Vue 3 TSX 组件中使用接口作为道具定义传递空对象

问题描述

我正在尝试使用接口在 tsx 中定义组件的道具,使用 defineComponent<MyPropInterface>,例如:

export interface MainProps {
  textContent: string;
}
export const Main = defineComponent<MainProps>({
  setup(props) {
    console.log(JSON.parse(JSON.stringify(props))); // prints {}
    return () => <main>{props.textContent}</main>; // renders: <main></main>
  },});

如果我使用 Vue 的对象 API 以认方式执行此操作:

export const Main = defineComponent({
  props: {
    textContent: String
  },setup(props) {
    console.log(JSON.parse(JSON.stringify(props))); // prints: { textContent: "my content" }
    return () => <main>{props.textContent}</main>; // renders: <main>my content</main>
  },});

道具输入正确,如果我将鼠标悬停在 props 上:

enter image description here

自动完成也有效:

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)