JavaScript 中if(!xxx)的作用

关于!(xx)的解释 我看博主都写的为true或者false

但是我个人得理解 加上! 就是如果为空

      if (!row.id) {
        //如果没有id  ...
      } else {
        //反之有id的操作  ..
      }

案例: 如果没有id 反之else

    //保存当前行数据
    async saveRow(row) {
      if (!row.id) {   //如果没有id
        var params = {
          name: row.name,
          remark: row.remark,
        };
        var res = await diseaseDataApi.createDisData(params);;    //新建
        if (res.code == 200) {
          this.$Message.success("保存成功");
          // 更新列表
          this.getDict();
        }
      } else {
        var params = {
          name: row.name,
          remark: row.remark,
          id: row.id,
        };
        var res = await diseaseDataApi.updateDisData(params);    //修改
        if (res.code == 200) {
          this.$Message.success("保存成功");
          // 更新列表
          this.getDict();
        }
      }
    },

猜你喜欢

转载自blog.csdn.net/weixin_57607714/article/details/125142069