Vue computed property with the method of recording parameters wording

computed attribute is calculated, how to do if the parameters? Can be written as follows

Vue.component("mulit-table-operation", {
  mixins: [mixin],
  template: `<span>
        <el-tooltip v-for="(item,index) in field"
                    :content="getItemName(item)"
                    :key="index"
                    placement="top">
            <el-button type=""
                        :class="getItemClass(item)"
                        size="mini"
                        circle
                        @click.stop.prevent="operation(item)">
            </el-button>
        </el-tooltip>
        </span>`,
  computed: {
    getItemName() {
      return function(item) {
        let r_name = item.b_name[0];
        if (item) {
          const p_name = item.p_name;
          const p_value = item.p_value;
          if (this.rowData && p_value) {
            let _this = this;
            p_value.forEach(function(a, index) {
              if (_this.rowData[p_name] == a) {
                r_name = item.b_name[index];
                return;
              }
            });
          }
        }
        return r_name;
      };
    },
    getItemClass() {
      return function(item) {
        let r_name = item.classname;
        if (item.classname instanceof Array) {
          r_name = item.classname[0];
          if (item) {
            const p_name = item.p_name;
            const p_value = item.p_value;
            if (this.rowData && p_value) {
              let _this = this;
              p_value.forEach(function(a, index) {
                if (_this.rowData[p_name] == a) {
                  r_name = item.classname[index];
                  return;
                }
              });
            }
          }
        }
        //特殊的业务处理,不影响其他组件的正常使用
        if (
          item.show_juje &&
          this.rowData.p_uid &&
          this.rowData.p_uid != ctool.getUserId()
        ) {
          r_name = "hideButton";
        }
        return r_name;
      };
    }
  }
});

And wherein getItemClass getItemName is brought into the reference, when the method defined computed, by way of an internal return of a function, but needs.

Reference: VUE calculating the property of the incoming parameters computed

Published 79 original articles · won praise 31 · views 110 000 +

Guess you like

Origin blog.csdn.net/liangcha007/article/details/104544692