未捕获的类型错误:不能读取属性'1'

Uncaught TypeError: Cannot read property '1'

本文关键字:读取 属性 不能读 不能 类型 错误      更新时间:2023-09-26

我有一个问题,只在chrome中出现,在firefox中正常工作没有问题

      computedStyle = getComputedStyle(element, ':before');
      content = computedStyle.getPropertyValue('content').slice(1, -1);
      // content --> NULL
      matchResult = content.match(/^'s*('d+)(?:'s?'.(.+))?'s*$/);
      if (matchResult) {
        numberOfColumns = matchResult[1];
        columnClasses = ((_ref = matchResult[2]) != null ? _ref.split('.') : void 0) || ['column'];
      } else {
        matchResult = content.match(/^'s*'.(.+)'s+('d+)'s*$/);
        columnClasses = matchResult[1];    // <-- Error here
        numberOfColumns = (_ref1 = matchResult[2]) != null ? _ref1.split('.') : void 0;
      }
      return {
        numberOfColumns: numberOfColumns,
        columnClasses: columnClasses
      };
    };
    add_columns = function(grid, items) {
      var columnClasses, columnsFragment, columnsItems, i, 

和console中的error is Uncaught TypeError: Cannot read property '1' of null

// ...
if (matchResult) {
    numberOfColumns = matchResult[1];
    columnClasses = ((_ref = matchResult[2]) != null ? _ref.split('.') : void 0) || ['column'];
} else if (matchResult = content.match(/^'s*'.(.+)'s+('d+)'s*$/)){
    columnClasses = matchResult[1];    // <-- Error here
    numberOfColumns = (_ref1 = matchResult[2]) != null ? _ref1.split('.') : void 0;
} else {
    columnClasses = numberOfColumns = null;
}
// ...

在处理数据之前,请确保matchResult不是null