vue 之 后端返回空字符串用 null 和 “”以及 undefind 判斷不到的問題


原文:

<!-- <span v-if="scope.row.buyer_credit_score != '' || scope.row.buyer_credit_score != null "> 買家:{{scope.row.buyer_credit_score}}</span>
<span v-if="scope.row.buyer_credit_score != '' || scope.row.buyer_credit_score != null && scope.row.seller_credit_score != '' || scope.row.seller_credit_score != null  "   > / </span>
 <span v-if="scope.row.seller_credit_score != '' || scope.row.seller_credit_score != null ">賣家 {{scope.row.seller_credit_score}}</span> -->
 
以上判斷都判斷不到 scope.row.buyer_credit_score == “ ” 是一個空字符串,所以改用了以下的方法
 
改版后的應用:
 
{{  此處寫你的方法名,例如:show_data(這里傳你要判斷的數據,例如:scope.row) }}
 
然后在 methods 的方法里寫:
 
  //判斷空值問題
        這里是寫你上面定義的方法名字,例如:show_data ( 這里是寫你傳進來的參數,例如:res  注:如果你傳多個參數,這里就得對應的增加多個參數,參數名字可以不用相同,只拿括號內的 參數進行對應判斷即可 ){
            if(res){
                if(res.buyer_credit_score ==="" &&res.seller_credit_score===""){
                    return "買賣雙方沒有評分"  // 這里是你要返回去要顯示的東西
                }
                    else if(res.buyer_credit_score &&res.seller_credit_score===""){
                        return '買家:'+res.buyer_credit_score
                }
                    else if(res.buyer_credit_score==="" &&res.seller_credit_score){
                        return '賣家:'+res.seller_credit_score
                }
                    else if(res.buyer_credit_score &&res.seller_credit_score){
                    return '買家:'+res.buyer_credit_score +'/'+'賣家:'+res.seller_credit_score  
                }

            }
        },


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM