如何使用 Vue 从样式绑定调用方法?



我写了以下代码:

<template v-slot="scope">
<div :class="getFuncationBarClass(scope)" :style="'{ --progress: `${getFunctionPercentage(scope)}` }'">{{getFuncationTotals(scope)}}</div>
</template>

出于某种原因,getFuncationBarClassgetFuncationTotals被调用,但getFunctionPercentage没有被调用。我尝试了其他一些:style变体,但它们都没有奏效。如何从样式绑定调用该方法?

在 Vue 中,你可以直接传递样式对象。您可以尝试:

<div :class="getFuncationBarClass(scope)" :style="{ '--progress': getFunctionPercentage(scope) }">{{getFuncationTotals(scope)}}</div>

最新更新