react js中的自调用函数?(与常规javascript一样)
我想调用react js中的自调用函数?(与常规javascript一样),javascript,reactjs,jsx,Javascript,Reactjs,Jsx,我想调用函数good,而不从事件调用它。它应该在页面打开后立即运行,就像在自调用javascript函数中一样。 从“React”导入React; 类应用程序扩展了React.Component{ 好的{ console.log('我在正常工作期间被触发') } render(){ console.log('我在渲染过程中被触发') 返回( 好的(); ); } } 导出默认应用程序; 几点: 1。您需要使用this关键字从任何其他函数调用任何函数 2.要将js代码放入JSX中,我们需要使用{
函数good
,而不从事件调用它。它应该在页面打开后立即运行,就像在自调用javascript函数中一样。
从“React”导入React;
类应用程序扩展了React.Component{
好的{
console.log('我在正常工作期间被触发')
}
render(){
console.log('我在渲染过程中被触发')
返回(
好的();
);
}
}
导出默认应用程序;
几点:
1。您需要使用this
关键字从任何其他函数调用任何函数
2.要将js
代码放入JSX
中,我们需要使用{}
这样写:
import React from 'react';
class App extends React.Component {
good(){
console.log('I was triggered during good')
return <div> Hello </div>
}
render() {
console.log('I was triggered during render')
return(
<div>
{this.good()}
</div>
);
}
}
从“React”导入React;
类应用程序扩展了React.Component{
好的{
console.log('我在正常工作期间被触发')
打招呼
}
render(){
console.log('我在渲染过程中被触发')
返回(
{this.good()}
);
}
}
检查反应文件:
查看这些答案以了解更多详细信息:
几点:
1。您需要使用this
关键字从任何其他函数调用任何函数
2.要将js
代码放入JSX
中,我们需要使用{}
这样写:
import React from 'react';
class App extends React.Component {
good(){
console.log('I was triggered during good')
return <div> Hello </div>
}
render() {
console.log('I was triggered during render')
return(
<div>
{this.good()}
</div>
);
}
}
从“React”导入React;
类应用程序扩展了React.Component{
好的{
console.log('我在正常工作期间被触发')
打招呼
}
render(){
console.log('我在渲染过程中被触发')
返回(
{this.good()}
);
}
}
检查反应文件:
查看这些答案以了解更多详细信息:
您还可以将生命周期方法用作componentDidMount(){}或componentWillMount(){}
componentWillMount将在装入组件之前触发,componentDidMount()将在装入组件之后触发。您也可以将生命周期方法用作componentDidMount(){}或componentWillMount(){}
componentWillMount将在安装组件之前触发,componentDidMount()将在安装组件之后触发。很好地解释了…:)这真的很有帮助,很好地解释了……:)这对汉克斯很有帮助。我会试试的。谢谢。我会试试那些。