Ant Design of Vue (3)Card 卡片动态加载后台数据

一.首先来建一个vue静态页面

 卡片 Card - Ant Design Vue (antdv.com)

 来看看页面效果

二.接下修改Card 动态加载显示后台数据

 1.这个是后台接口返回数据

 2.接口有了,那接下来进行页面改造。

 3.接口改造完成,接下来调用接口,加载数据。

    获取后台数据的方式很多种,可以用自己拿手的方式进行数据获取,这里只是提供实现的思路,可能不是最挂的方式,各位可以积极指出。

4.数据加载出来了,让它自动刷新显示实时数据

参考文章:vue项目中实现定时刷新页面(重新渲染数据实时更新) - 飞翔的蜗牛~ - 博客园 (cnblogs.com)

5.实现页面代码

<script>
import { infoAllBufferApi } from '@/api/main'
export default {
    data(){
        return {
            content:null,//卡片内容
             timer:null, //定时器名称
        }
    },
    mounted(){
    this.materielinfoAllBuffer();
    this.timer = setInterval(() => {
        setTimeout(this.materielinfoAllBuffer, 0)
    }, 8000)
    },
    methods:{
        materielinfoAllBuffer(){
        infoAllBufferApi('materielInfoAllBuffer').then(res => {
            if (res.code == 0) {
            console.log("原始数据2"+res.data);
            var jsonobj= eval('(' +res.data + ')');//解析Json字符串
            if(jsonobj.data!=null){
            this.$set(this.$data,'content',jsonobj.data); //展示数据在卡片
            }else{
            this.content="接口出错了";
            }
        }
        }).catch(err => {
        console.log('err:', err)
        })
        }
    },
    beforeDestroy(){
    clearInterval(this.timer);
    this.timer = null;
  }
}
</script>

 6.页面效果

 三.数据展示出来了,但是状态那一列,我要根据根据对应的数字,显示中文名称,并且显示不同的颜色

参考文章:(32条消息) vue根据不同文字显示不同颜色_茶理li-CSDN博客

 1.页面修改:

2.完整的页面代码

<script>
import { infoAllBufferApi } from '@/api/main'
export default {
    data(){
        return {
            content:null,//卡片内容
             timer:null, //定时器名称
        }
    },
    //根据状态更改颜色
   computed: {
    activation() {
    return (icontent) => { // 使用JavaScript闭包,进行传值操作
    if (icontent ==4){
        return {'color':'red'}
    }
    else if (icontent ==7){
        return {'color':'blue'}
    }
    else if (icontent ==5){
        return {'color':'DeepPink'}
    }
    else if(icontent==2){
        return {'color':'Lime'}
    }
    else if(icontent==0){
        return {'color':'LightSeaGreen'}
            }
        }
    }
    },  
    mounted(){
    this.materielinfoAllBuffer();
    this.timer = setInterval(() => {
        setTimeout(this.materielinfoAllBuffer, 0)
    }, 8000)
    },
    methods:{
        materielinfoAllBuffer(){
        infoAllBufferApi('materielInfoAllBuffer').then(res => {
            if (res.code == 0) {
            console.log("原始数据2"+res.data);
            var jsonobj= eval('(' +res.data + ')');//解析Json字符串
            if(jsonobj.data!=null){
            this.$set(this.$data,'content',jsonobj.data); //展示数据在卡片
            }else{
            this.content="接口出错了";
            }
        }
        }).catch(err => {
        console.log('err:', err)
        })
        }
    },
    beforeDestroy(){
    clearInterval(this.timer);
    this.timer = null;
  }
}
</script>

 3.页面效果

四.颜色对照表

【C#】Color颜色对照表 - Endv - 博客园 (cnblogs.com)

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 10
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小丫头呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值