react render if 的使用
react 在Render里做判断,如果a就渲染单位:吨,如果b就渲染单位台。
示例:
import React from 'react';
class YourComponent extends React.Component {
render() {
const { a, b } = this.props; // 假设a和b是组件的props
let unit;
if (a) {
unit = '吨';
} else if (b) {
unit = '台';
}
return (
<div>
单位:{unit}
</div>
);
}
}
export default YourComponent;