react 组件抽离,封装
2021-01-03 本文已影响0人
ticktackkk
子组件
核心就是父组件给子组件传props,没啥好说的
import React from 'react';
class MyComponents extends React.Component {
constructor(props) {
super(props);
this.state = {}
console.log(props);
}
render() {
return (
<div>
<img src={this.props.src}></img>
</div>
);
}
}
export default MyComponents;
父组件
import React, { useEffect, useState } from 'react';
import MyComponents from './components/uploder'
class App extends React.Component {
constructor(props) {
super(props);
this.state = { }
}
render() {
return (
<MyComponents src='https://img-bss.csdn.net/1606271766185.jpg'></MyComponents>
);
}
}
export default App;