vue 判断数据中是空数据赋值'--';

在写项目时,遇到表格如果有空数据,显示‘--’的需求:


1.png
export default {
        data() {
            return {
                uuid:'',
                datas:[],
            }
        },
        mounted: function () {
            this.uuid = getStore('uuidTest').aa;
            this.get_market();
        },
        methods: {
            get_market(){
                this.$axios.get('/website/websiteClient/queryMarket/?wareKindid='+this.tradeType,
                    {
                        headers: {
                            'UUID': this.uuid
                        }
                    }
                )
                    .then(res => {
                        if(res.data.code == 0){
                            if(res.data.data.length !== 0){
                                this.showA = false;
                                res.data.data.forEach((item) => {
                                    if(item.NEWPRICE == 0.00 || item.NEWPRICE == ''){
                                        item.NEWPRICE= '--';
                                    }
                                    if(item.HIGHPRICE == 0.00 || item.HIGHPRICE == ''){
                                        item.HIGHPRICE= '--';
                                    }
                                    if(item.LOWPRICE == 0.00 || item.LOWPRICE == ''){
                                        item.LOWPRICE= '--';
                                    }
                                    if(item.BUYPRICE1 == 0.00 || item.BUYPRICE1 == ''){
                                        item.BUYPRICE1= '--';
                                    }
                                    if(item.SALPRICE1 == 0.00 || item.SALPRICE1 == ''){
                                        item.SALPRICE1= '--';
                                    }
                                });
                                this.datas = res.data.data;
                            }
                        }

                    })
            }
        },
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容