静态调用组件与refs问题
-
1、在taro低版本时,自定义一个组件,如ComponentA组件,可以自定义static方法,然后在constructor中,将static方法绑定到当前对象的某个方法,以此来实现类似静态调用的情况
但在高版本taro中,编译成百度小程序,一直在报找不到ComponentA,这个是什么情况?
export default class ComponentA extends Component<IProps, IState>{ static testFunction: Function constructor(props) { super(props) ComponentA.testFunction = this.testFun.bind(this) } testFun(){//....}
使用时:
console.log(ComponentA)
报错:
Uncaught ReferenceError: ComponentA is not defined
2、由于1方案出现问题,继而尝试用ref来获取自定义组件ComponentA,按照文档所写,打印refs一直为null。同时发现如果是taro组件,用ref是正常的,但自定义组件refs无效