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

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>
主站蜘蛛池模板: 龙口市| 洪江市| 栖霞市| 定陶县| 潼南县| 峨眉山市| 安岳县| 万宁市| 永善县| 梧州市| 郁南县| 武城县| 徐州市| 太原市| 迭部县| 常德市| 盐山县| 自治县| 永寿县| 莱阳市| 樟树市| 司法| 濮阳市| 澄江县| 馆陶县| 金寨县| 大渡口区| 白玉县| 乡城县| 桂林市| 南雄市| 志丹县| 玉门市| 竹溪县| 舞钢市| 太康县| 郁南县| 锡林浩特市| 怀化市| 丰县| 镇宁|