当前位置:网站首页>1-3 components and modules

1-3 components and modules

2022-04-23 16:59:00 Endless cake

Components and modules

modular
1. Providing specific functions to the outside world js Program , It's usually a separate js file
2. Why should it be disassembled into modules : With the increase of business , The code is getting more complicated
3. Reuse js, simplify js, Provide js efficiency

Components
1. A collection of code and resources used to achieve local functional effects (html/css/js/image) etc.
2. Used to improve the reuse rate of code , Simplify the code , Improve operational efficiency

Functional component
What to pay attention to :
1. Component initial must be uppercase
2. Function must have a return value
3. Labels must be used when using

<div id='text'></div>
      // Functional component 
      function Demo() {
        // Here this yes undefined, because babel It turns on strict mode . In strict mode, it is forbidden to this Point to window
        console.log(this);
        return <h2>sjsoj</h2>;
      }
      ReactDOM.render(<Demo />, document.getElementById("text"));
	 /*
       Yes ReactDOM.render after .
      1.react Resolved component label , eureka Demo Components 
      2. Then it is found that the component is defined by the function , Subsequent call function , The virtual machine that will be returned DOM, Then it appears on the page 
      */

版权声明
本文为[Endless cake]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230554519835.html