key值是样式名,value值是data中绑定的属性
当isDelete为true的时候,delete就会进行渲染
<div id="app"> <h3>Class绑定 v-bind:class 或者 :class </h3> <p v-bind:class="activeClass">字符串表达式</p> <p :class="{delete:isDelete,error:hasError}">对象表达式</p> <p :class="['active','error']">数组表达式</p:> </div> <script> var vm = new Vue({ el:'#app', data: { activeClass:'active', isDelete:true, hasError:true }, methods:{ // 指定事件处理函数 }, computed:{ // 定义计算属性选项 } }); </script>
style样式绑定
<h3>Style绑定,v-bind:style或:style</h3> <p :style="{color:activeColor,fontSize:fontSize + 'px'}">Style绑定</p> data:{ activeColor:'red', fontSize:20 }