<div class="cart-thead"> <div class="t-checkbox"> <input type="checkbox" name="" id="" class="checkall"> 全选 </div> <div class="t-goods">商品</div> <div class="t-price">单价</div> <div class="t-num">数量</div> <div class="t-sum">小计</div> <div class="t-action">操作</div> </div>改成组件,把数据放在data中
时间: 2024-03-25 09:37:54 浏览: 59
好的,你可以参考下面的代码将这段 HTML 代码改成一个组件,并将数据放在 `data` 中:
```js
// CartThead.js
import React from 'react';
const data = {
checkbox: '全选',
goods: '商品',
price: '单价',
num: '数量',
sum: '小计',
action: '操作'
};
function CartThead() {
return (
<div className="cart-thead">
<div className="t-checkbox">
<input type="checkbox" name="" id="" className="checkall" /> {data.checkbox}
</div>
<div className="t-goods">{data.goods}</div>
<div className="t-price">{data.price}</div>
<div className="t-num">{data.num}</div>
<div className="t-sum">{data.sum}</div>
<div className="t-action">{data.action}</div>
</div>
);
}
export default CartThead;
```
然后在其他组件中引入 `CartThead` 组件即可:
```js
// OtherComponent.js
import React from 'react';
import CartThead from './CartThead';
function OtherComponent() {
return (
<div>
<CartThead />
{/* 其他内容 */}
</div>
);
}
export default OtherComponent;
```
阅读全文