react中写动态标签,render方法中如何使用if else 判断

Isoke ·
更新时间:2024-09-20
· 744 次阅读

在render()中循环数据,根据数据不同展示标签不同

import React from 'react'; const quanList=[ { id:1, buy_price:1,//购买券的价格 quan_price:30,//可抵扣价格 quanName:'仅限(学习机)商品使用', on_time:'2020-11-01', off_time:'2020-11-30', isHave:false, }, { id:2, buy_price:3,//购买券的价格 quan_price:30,//可抵扣价格 quanName:'通用券', on_time:'2020-11-01', off_time:'2020-11-30', isHave:true, }, ]; export default class QuanList extends React.Component{ constructor(props){ super(props); this.state={ data:quanList, } } render(){ return(
{this.state.data.map(quan=>(
¥{quan.buy_price}(可抵扣{quan.quan_price}元)
{quan.quanName}
{quan.on_time} 至 {quan.off_time}
{quan.isHave ?


:


} {/*


*/} {/*


*/}
))}
) } }

作者:qq_41315539



IF ELSE 动态 标签 React

需要 登录 后方可回复, 如果你还没有账号请 注册新账号