创建根据表格行而变化的元素 UI 工具提示内容

问题描述

我有一个方法可以根据元素 UI 表中列的值将字符串返回到工具提示内容,但是它只返回第一列的值,而不是在悬停时更改。

<el-table-column label="Service Lines / MSDRG" prop="code" sortable min-width="120">
  <template slot-scope="slotData">
    <el-tooltip 
      effect="dark" 
      placement="top-start" 
      :content="returnSvclinesValue(slotData.row.code,name)"
    >
    <span>{{ slotData.row.code }}</span>
    </el-tooltip>
   </template>
</el-table-column>

这是returnSvclineValue(code,name)方法

returnSvclinesValue: function(code,name) {
  const svclinesTrimmedByName = svclines.find(i => i.label == name && i.value == name)
  const svclineValue = svclinesTrimmedByName.children.find(l => l.value = code )
  return svclineValue.label
}

对于方法 returnSvclinesValue(code,name),它有效,我只需要它根据行的代码呈现不同的内容..是否有某种类型的解决方法

解决方法

使用如下所述的参数创建一个计算属性:

computed:{
   returnSvclinesValue(){
      return (code,name)=> {
       const svclinesTrimmedByName = svclines.find(i => i.label == name && i.value == name)
       const svclineValue = svclinesTrimmedByName.children.find(l => l.value == code )
       return svclineValue.label
     }
  }

}