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

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>
主站蜘蛛池模板: 天峨县| 环江| 雷山县| 湘西| 平邑县| 建瓯市| 乌兰浩特市| 巴林右旗| 高清| 广元市| 阿鲁科尔沁旗| 沿河| 阳谷县| 凉城县| 富顺县| 农安县| 灌阳县| 凤凰县| 晋中市| 黔东| 新宾| 石楼县| 乐平市| 安福县| 重庆市| 沁源县| 紫金县| 阿拉尔市| 当涂县| 确山县| 延安市| 昌都县| 娱乐| 天祝| 榆林市| 航空| 马尔康县| 新疆| 忻州市| 和顺县| 米脂县|