//后端的数据在data中
<uni-list v-for="(item,index) in data" :key="index" class="box">
<view class="value" :style="{ color: getStatusColor(item.status) }">
{{ getStatusText(item.status) }}
</view>
</uni-list>
data() {
return {
statusMapping: {
'0': { color: 'green', text: '正常' },
'1': { color: 'yellow', text: '注意' },
'2': { color: 'red', text: '警告' },
// 你可以根据需要添加更多的状态
// '3': { color: 'blue', text: '其他状态' },
// ...
},
};
}
methods: {
getStatusColor(status) {
return this.statusMapping[status]?.color || 'default-color'; // 如果找不到映射,使用默认颜色
},
getStatusText(status) {
return this.statusMapping[status]?.text || '未知状态'; // 如果找不到映射,显示“未知状态”
}
}