验证数据是否为空

验证数据是否为空

定义函数

export function notEmpty(params) {
  var verification = Object.prototype.toString.call(params);
  if(verification == '[object Undefined]' || verification == '[object Null]'){
    return false
  }else if(verification == '[object Boolean]'){
    if(params){
      return true
    }else{
      return false
    }
  }else if(verification == '[object Number]' || verification == '[object Date]'){
    return true
  }else if(verification == '[object String]'){
    if(params == "") {
      return false;
    } else {
      return true;
    }
  }else if(verification == '[object Object]'){
    if(Object.keys(params) == 0){
      return false
    }else{
      return true
    }
  }else if(verification == '[object Array]'){
    if(params.length == 0){
      return false
    }else{
      return true
    }
  }else if(verification == '[object Function]' || verification == '[object RegExp]' || verification == '[object Error]' || verification == '[object Arguments]'){
    console.log('特殊类型')
    return false
  }
}

挂载

import * as helper from './xxx/xxx'
Vue.prototype.$at = helper

使用

<view>{{$at.notEmpty(1) ? 1 : '--'}} 具</view>

 132 total views,  4 views today

Revisions

Comments are closed.