代码之家  ›  专栏  ›  技术社区  ›  VAAA

Vuejs动态图标类

  •  -2
  • VAAA  · 技术社区  · 7 年前

    我有以下内容 i 元素:

    <i class="icon-user custom-style test"
              v-if="employee.status === 0 && this.employeeType === 'admin'">
        </i>
    

    我想替换类图标用户,具体取决于 v-if 相同条件。

    所以,如果 employee.status === 0 && this.employeeType === 'admin' 图标类应该是 icon-user ,否则应该是 icon-home

    有什么线索吗?

    1 回复  |  直到 7 年前
        1
  •  1
  •   niclas_4    7 年前

    computed: {
      classObject: function() {
        if(this.employee.status === 0 && this.employeeType === 'admin')
        {
          return "icon-user";
        }
        else return "icon-home"
    <i v-bind:class="classObject"></i>

    这应该是一个解决方案, a lot of other options in the docs.