创建类
class TestApi1 {
private age: number = 1;
private sex: string = '女';
constructor(age: number) {
this.age = age;
}
public getTestApiMethod() {
if (this.age === 1) {
} else {
}
}
}
export {
TestApi1,
}
如何使用:
import React from 'react';
import { TestApi1 } from "./testAPI"
class Test extends React.Component<any, any> {
constructor(props: any) {
super(props);
this.state = {
}
}
getTestApiMethod = () => {
// 第二种
let getTestApiMethod1 = new TestApi1(1).getTestApiMethod()
let getTestApiMethod2 = new TestApi1(2).getTestApiMethod()
}
render() {
return (
<div></div>
)
}
}
export default Test