📜  对象属性中的打字稿字符串 - 打字稿代码示例

📅  最后修改于: 2022-03-11 14:48:22.291000             🧑  作者: Mango

代码示例1
protected get ButtonClass(): object {
    const buttonClass = {
      'cursor-pointer hover:shadow focus:shadow': this.Enabled,
      'opacity-40 cursor-not-allowed': !this.Enabled,
      'whitespace-no-wrap': !this.LineBreaks
    }
    // The below allows you to define object properties based on a variable.
    // If you were to assign them in the snippet above, it would cause an error.
    buttonClass[`hover:${this.Color.FocusColorClass}`] = this.Enabled;
    buttonClass[`focus:${this.Color.FocusColorClass}`] = this.Enabled;
    buttonClass[`active:${this.Color.ActiveColorClass}`] = this.Enabled;
    return buttonClass;
  }