之前只是用过普通的方法写变量,这次加上循环加判断,直接上代码
`<div class="description">
<div class="mt-3 detail">
名称:${list.name}<br />
价格${unitName}:${list.price}
${list.increase.split(",").map(value=>{
if(value>=0){
return `<span style="color:red">↑${value}</span>`
}else{
return `<span style="color:green">↓${value}</span>`
}
})}
</div>
</div>`
注意:主要是map的使用,需要用map,将值return出去,如果使用foreach则不报错一直返回undefined
补充--echars中自定义内容使用
formatter: (params)=>{
let list = []
let listItem = ''
params.map(value=>{
list.push(`
<div style="display:flex;justify-content: space-between;align-items: center">
<span>
<span style="background:${value.color};width:10px;height:10px;border-radius:5px;display:inline-block"></span>
新增${value.seriesName}
</span>
<span>${value.value}</span>
</div>
<div style="display:flex;justify-content: space-between;align-items: center">
<span>
<span style="background:${value.color};width:10px;height:10px;border-radius:5px;display:inline-block"></span>
扫码总${value.seriesName.slice(2,4)}
</span>
<span>${value.data.total}</span>
</div>`)
})
listItem = list.join('')
return (`<div style="min-width:150px">
<div>
${params[0].name}
</div>
${listItem}
</div>`)
}
注意:不要直接循环最外层div,只能有一个根节点,循环拼接即可