vue绑定class与行间样式style详解
一、绑定class属性的方式
1、通过数组的方式,为元素绑定多个class
window.onload=function(){
varc=newVue({
el:'#box',
data:{
red_color:'red',
bg_color:'bg'
}
});
}
thisisateststring
上例为span绑定2个class,通过设定red_color和bg_color的值,找到对应的class类名
2、通过控制class的true或者false,来使用对应的class类名,true:使用该class, false:不使用该class
window.onload=function(){
varc=newVue({
el:'#box',
data:{
}
});
}
thisisateststring
3、这种方式,跟第二种差不多,只不过是把class的状态true/false用变量来代替
window.onload=function(){
varc=newVue({
el:'#box',
data:{
r:true,
b:false
}
});
}
thisisateststring