uniapp: 动态绑定/加载/切换元素class的一种有效姿势


试过两个办法。

第一种:


但是这种方法报错了。
报错信息:

Property or method "xxx" is not defined on the instance but referenced during render.Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

说我的class还没有定义。

正确姿势

在class里面写个方法,方法返回这个class名。

1.页面:


方法里面可以传参。

2.在method里写这个方法

setClass:function(a,b){
  if(a>b){
    return "classa";
   }else {
    return "classb";
     }
}

完美解决!

相关