官术网_书友最值得收藏!

Class binding

How we'll approach this is to dynamically bind thecontractedclass. Let's create acontracteddata propertyand set its initial value totrue.

app.js:

data: {
  ...
  contracted: true
}

Like our style binding, we can bind this class to an object. In the expression, thecontractedpropertyis the name of the class to be bound, thecontractedvalueis a reference to the data property of that same name, which is a Boolean. So if thecontracteddata propertyevaluates totrue, that class will be bound to the element, and if it evaluates to false, it will not.

index.html:

<p v-bind:class="{ contracted: contracted }">{{ about }}</p>

It follows that when the page loads the contracted class is bound:

<p class="contracted">...</p>
主站蜘蛛池模板: 收藏| 平安县| 松潘县| 乐亭县| 公安县| 买车| 汨罗市| 两当县| 建阳市| 台湾省| 石渠县| 大兴区| 宁都县| 小金县| 兴安盟| 蓬安县| 山阴县| 腾冲县| 邯郸市| 阿合奇县| 绵阳市| 探索| 两当县| 和田市| 普宁市| 元谋县| 新化县| 齐河县| 韶关市| 和静县| 离岛区| 德惠市| 三明市| 古田县| 德阳市| 商城县| 绥芬河市| 北川| 如皋市| 东乡族自治县| 斗六市|