下面的使用有问题,具体参见此方法
Class(属性绑定)
1、绑定对象->动态切换
<style>.test1{color:red;}.test2{background:yellow;}</style><div :class="{test1 :a , test2: b}"Hello</div>...data:{a:true,//根据true/false判断是否执行classb:true}在data中定义两个变量,a控制test1样式,b控制test2样式,当都为true时,后者test2的样式会在相同属性时覆盖test1
2、数据对象绑定
<style>
.test1{
color:red;
}
.test2{
background:yellow;
}
</style>
<div :class="testObj">HELLO?</div>
data:{
testObj:{//对象中直接定义属性
color:red;
background:yellow;
}
}
3、数组绑定
<div :class="[test1Class,test2Class]">HELLO?</div>
data:{
test1Class:test1,
test2Class:test2
}
同时支持两个class属性
Style(样式绑定)
1、直接绑定
<div :style="{color:cl,background:bk}">你好吗?</div></div>
2、对象绑定
<div :style="testObj">你好吗?</div>
data:{
testObj:{
color:red;
background:yellow;
}
}
3、数组绑定
<div :style="[test1,test2]">你好吗?</div>
data:{
test1{
color:'red'
}
test2{
background:'yellow'
}
}
