- 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>
推薦閱讀
- Oracle WebLogic Server 12c:First Look
- Progressive Web Apps with React
- 架構不再難(全5冊)
- Network Automation Cookbook
- Mastering Python High Performance
- Learning Selenium Testing Tools(Third Edition)
- Working with Odoo
- Instant Lucene.NET
- Python語言實用教程
- 現代C++編程實戰:132個核心技巧示例(原書第2版)
- Mastering Python Design Patterns
- 零基礎學C語言第2版
- Cocos2d-x Game Development Blueprints
- Unity 2018 Augmented Reality Projects
- JavaScript程序設計:基礎·PHP·XML