(1)第一种方法
var test="";
if(test==""||test==null||test==undefined){
alert("为空");
}
(2)第二种方法
var test="";
if(!test){
alert("为空");
}
(1)第一种方法
var test="";
if(test!=""&&test!=null&&test!=undefined){
alert("不为空");
}
(2)第二种方法
var test="";
if(!!test){
alert("不为空");
}
function isNil(value) {
return value === null || value === undefined
}
if (isNil(num)) {
...
}
import {isNil} from 'lodash'
if (isNil(num)) {
...
}
??saveRow (record) {
// 将错误提示的逻辑用箭头函数(一定要箭头函数,为了this能穿透到上一级作用域)包装
const tip = ()=> {
this.tableLoading = false
this.$message.error('请填写完整信息。')
return
}
const { num, id } = record
num ?? tip() // ?? 操作符只会在 num 为null或undefined 执行 ?? 后面的语句
}
[slice、splice、split 三者的区别](https://www.notion.so/slice-splice-split-9912b632d58e4611901d3e41b8cf1fb8)