vue 判断不为null

var startdate = localStorage.getItem('startdate')
var enddate = localStorage.getItem('enddate')

  if (startdate !== 'null') {
    this.listQuery.startdate = startdate
  }

这是想问啥

改成这样


if (startdate !==null) {
    this.listQuery.startdate = startdate
  }

  1. 写个方法来判断

function isEmpty(value) {
                if (value == null || value == undefined || value == "" || value == 'undefined' || value=='null' || value=='Null') {
                    return true;
                }
                return false;
            }

  if (!isEmpty(startdate)) {
    this.listQuery.startdate = startdate
  }

startdate != null

null不要加“”

你用startdate == 'null' 判断是它是不是这个字符串,你要把引号去掉,你需要判断的是类型

if (startdate !== null) {
this.listQuery.startdate = startdate
}