【关于组件的定义与导出使用】

1、使用

type a = {
  title?: string;
}

import Test,{Gran} from "@/pages/test/test";

export default (props: a) => {
  const test: a = {
    name: 'sunwukong',
    title: 'aa',
    'aa': 1
  }

  console.log('a', typeof props)

  return (
    <div>aaa
      <button onClick={() => {
        Test.sayHello();
        Test()
      }
      }>say hello</button>
      <Test/>
      <Test.Gran/>
      <Gran />
    </div>
  )
}

2、定义

const Test = () => {
  return (
    <div id={'app'}>我是子组件</div>
  )
}

Test.sayHello = () => {
  const documnet = document.getElementById('app');
  const span = document.createElement('span');
  span.innerText = 'hello aaaaaaaa'
  documnet.appendChild(span)

}

export const Gran = () => {
  return '我是孙组件'
}
Test.Gran = Gran;

export default Test;

你可能感兴趣的:(javascript,前端,typescript)