- Full-Stack Vue.js 2 and Laravel 5
- Anthony Gore
- 105字
- 2021-07-02 19:57:21
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>
推薦閱讀
- Mastering JavaScript Functional Programming
- PyTorch自動駕駛視覺感知算法實戰
- 程序員面試筆試寶典
- Mastering Natural Language Processing with Python
- Spring Boot+Spring Cloud+Vue+Element項目實戰:手把手教你開發權限管理系統
- Python Geospatial Development(Second Edition)
- C語言程序設計
- Salesforce Reporting and Dashboards
- Python High Performance Programming
- Practical Game Design with Unity and Playmaker
- Extreme C
- Learning Unreal Engine Game Development
- HTML5移動Web開發
- Java EE項目應用開發
- C語言王者歸來