1***@163.com
1***@163.com
  • 发布:2024-11-20 14:52
  • 更新:2024-11-21 14:08
  • 阅读:286

各位大神,请问uni-table里面得uni-tr怎么设置动态样式添加背景色

分类:uni-app
2024-11-20 14:52 负责人:无 分享
已邀请:
套马杆的套子

套马杆的套子 - 没有解决不了的问题,只有解决不完的问题

:style 或者:class不行么?

套马杆的套子

套马杆的套子 - 没有解决不了的问题,只有解决不完的问题

你看下,我刚试的,可以啊

<template>  
    <view>  

        <view class="uni-container">  
            <uni-table ref="table">  
                <uni-tr>  
                    <uni-th width="150" align="center">日期</uni-th>  
                    <uni-th width="150" align="center">姓名</uni-th>  

                </uni-tr>  
                <uni-tr v-for="(item, index) in tableData" :key="index">  
                    <uni-td>{{ item.date }}</uni-td>  
                    <uni-td >  
                        <view class="name" :class="[tdBg(index)]">{{ item.name }}</view>  
                    </uni-td>  
                </uni-tr>  
            </uni-table>  

        </view>  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  
                tableData: [{  
                    "date": "2020-09-01",  
                    "name": "Dcloud1",  
                    "address": "上海市普陀区金沙江路 1518 弄"  
                }, {  
                    "date": "2020-09-02",  
                    "name": "Dcloud2",  
                    "address": "上海市普陀区金沙江路 1517 弄"  
                }, {  
                    "date": "2020-09-03",  
                    "name": "Dcloud3",  
                    "address": "上海市普陀区金沙江路 1519 弄"  
                }]  
            };  
        },  
        methods:{  
            tdBg(index){  

                if(index==1){  
                    return 'red-cls'  
                }else{  
                    return 'gr-cls'  
                }  
            }  
        }  
    };  
</script>  

<style>  
    .red-cls{  
        background-color: red;  
    }  
    .gr-cls{  
        background-color: green;  
    }  

</style>
  • 1***@163.com (作者)

    谢谢 我试过这个方法了 整体样式不太行 直接改uni-table源码解决了

    2024-11-21 15:40

要回复问题请先登录注册