Vue-使用道具分配类的方程式

时间:2019-04-17 22:30:46

标签: vue.js vuejs2

根据要传递给数据表的数据,我有一个数据表需要应用一个类。

我只想在绑定的类中运行方程式,但是我不知道怎么做。

我的代码可能更有意义。我有这个简单的表:

<template slot="items" slot-scope="props">
  <td :class="{ threshold: true }">{{ props.item.inventory_amount}}</td>
  <td :class="{ threshold: threshold_hit }">{{ props.item.threshold}}</td>
</template>

然后我要根据此计算将threshold类分配给这些行:

props.item.inventory_amount > props.item.threshold

这可以正常工作并返回true或false:

<td> {{ props.item.inventory_amount > props.item.threshold }}</td>

但这失败了:

<td :class="{ threshold: props.item.inventory_amount > props.item.threshold}">{{ props.item.inventory_amount}}</td>

如何在类绑定中运行该方程式?

1 个答案:

答案 0 :(得分:0)

您的语法

:class=`{
  '_threshold': props.item.inventory_amount > props.item.threshold
}`