【问题标题】:How to fix TypeError: CSS2Properties doesn't have an indexed property setter for '0'如何修复 TypeError:CSS2Properties 没有“0”的索引属性设置器
【发布时间】:2017-05-09 06:02:54
【问题描述】:

我正在使用 reactJs 和 Material UI 进行应用程序开发。 当我在 Mozilla Firefox 中打开应用程序时,它给了我一个错误
"TypeError: CSS2Properties doesn't have an indexed property setter for '0'"
并且我的导航不起作用。请给我任何解决方案。

var CSSPropertyOperations = {

  /**
   * Serializes a mapping of style properties for use as inline styles:
   *
   *   > createMarkupForStyles({width: '200px', height: 0})
   *   "width:200px;height:0;"
   *
   * Undefined values are ignored so that declarative programming is easier.
   * The result should be HTML-escaped before insertion into the DOM.
   *
   * @param {object} styles
   * @param {ReactDOMComponent} component
   * @return {?string}
   */
  createMarkupForStyles: function (styles, component) {
    var serialized = '';
    for (var styleName in styles) {
      if (!styles.hasOwnProperty(styleName)) {
        continue;
      }
      var styleValue = styles[styleName];
      if (false) {
        warnValidStyle(styleName, styleValue, component);
      }
      if (styleValue != null) {
        serialized += processStyleName(styleName) + ':';
        serialized += dangerousStyleValue(styleName, styleValue, component) + ';';
      }
    }
    return serialized || null;
  },

  /**
   * Sets the value for multiple styles on a node.  If a value is specified as
   * '' (empty string), the corresponding style property will be unset.
   *
   * @param {DOMElement} node
   * @param {object} styles
   * @param {ReactDOMComponent} component
   */
  setValueForStyles: function (node, styles, component) {
    if (false) {
      ReactInstrumentation.debugTool.onHostOperation({
        instanceID: component._debugID,
        type: 'update styles',
        payload: styles
      });
    }

    var style = node.style;
    for (var styleName in styles) {
      if (!styles.hasOwnProperty(styleName)) {
        continue;
      }
      if (false) {
        warnValidStyle(styleName, styles[styleName], component);
      }
      var styleValue = dangerousStyleValue(styleName, styles[styleName], component);
      if (styleName === 'float' || styleName === 'cssFloat') {
        styleName = styleFloatAccessor;
      }
      if (styleValue) {
        style[styleName] = styleValue;
      } else {
        var expansion = hasShorthandPropertyBug && CSSProperty.shorthandPropertyExpansions[styleName];
        if (expansion) {
          // Shorthand property that IE8 won't like unsetting, so unset each
          // component to placate it
          for (var individualStyleName in expansion) {
            style[individualStyleName] = '';
          }
        } else {
          style[styleName] = '';
        }
      }
    }
  }

};

在“style[styleName] = styleValue;”上遇到错误

【问题讨论】:

    标签: css reactjs cross-browser material-ui


    【解决方案1】:

    在 React(不是 React Native)中,合并样式可以使用 javascript 函数 Object.assign()

    var textStyles = Object.assign({}, 
     styles.tile,
     tile.position,
     styles.emptytile,
     );
     <div key={tile.id} style={textStyles}>
    

    检查您是如何使用这些样式的。

    【讨论】:

    • 我用过 style --- 'const styles = { menuItemStyle: { fontSize:12, }, listItemStyle: { fontSize:12, }, }; menuItemStyle={styles.menuItemStyle}'
    猜你喜欢
    • 1970-01-01
    • 2019-09-15
    • 1970-01-01
    • 2018-03-14
    • 2019-12-05
    • 2019-10-05
    • 2019-07-09
    • 2021-02-07
    • 2019-10-23
    相关资源
    最近更新 更多