详解vue.js之绑定class和style的示例代码

2020-06-14 06:04:17易采站长站整理

效果,点击去掉class,会调用removeClass函数,去掉classArray数组的最后一项,第一次,去掉’red’,字体颜色由红变黑,再点,去掉’big’,字体变小。

二、绑定内联style

此时此刻,我一边看着本页旁边的那个Vue api文档学,一边到这里卖,装逼的感觉真爽o(^▽^)o

html


<div id="styleBind">
<span :style="{color:theColor,fontSize:theSize+'px'}" @click="bigger">styleBind</span>
</div>

css

这个不需要css。。。

js


var app12=new Vue({
el:'#styleBind',
data:{
theColor:'red',
theSize:14
},
methods:{
bigger:function(){
this.theSize+=2;
}
}

});

除了传入对象字面量以外,也可以传入对象引用和数组给V-bind:style