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

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>
主站蜘蛛池模板: 寿阳县| 玉屏| 大姚县| 麻城市| 罗平县| 淮滨县| 怀宁县| 遵义市| 手机| 广灵县| 海盐县| 龙岩市| 黄山市| 乳山市| 西峡县| 来凤县| 大邑县| 开阳县| 临高县| 贵港市| 苏尼特右旗| 钟山县| 孝感市| 永新县| 松阳县| 绥中县| 土默特右旗| 神池县| 屏边| 宝坻区| 岚皋县| 保靖县| 佳木斯市| 佛教| 德兴市| 泰来县| 岑溪市| 门源| 武宣县| 古交市| 长葛市|