根据最终决定的效果,您有多种选择。
这是最简单的解决方案。在watch
吸气剂上使用computed
er和条件类来设置值的样式。
data: {
myValue: {
prev: 150,latest: 100
}
},computed: {
valueInStore() {
return this.$store.getters.value
}
},watch: {
valueInStore(newValue,oldValue) {
this.myValue.prev = oldValue
this.myValue.latest = newValue
}
}
然后显示正确的CSS类
<div :class="getColorClass(myValye)">{{ myValue.latest }}</div>
...
methods: {
// method instead of computed since you were talking about multiple values
getColorClass(foo) {
return this.myValue.prev < this.myValue.latest ? 'green' : 'red'
},}
根据您的需求,您可能需要针对prev == latest
情况进行调整。
现在,您可以在.green
和.red
类中使用所需的任何CSS样式或动画。
本文链接:https://www.f2er.com/3169414.html