- Full-Stack Vue.js 2 and Laravel 5
- Anthony Gore
- 118字
- 2021-07-02 19:57:18
Style binding
To set a background image, we must provide the URL as a property in a CSS rule like this:
.header .header-img { background-image: url(...); }
Obviously, our header image should be specific to each inpidual listing, so we don't want to hard code this CSS rule. Instead, we can have Vue bind the URL from data to our template.
Vue can't access our CSS style sheet, but it can bind to an inlinestyleattribute:
<p class="header-img" style="background-image: url(...);"></p>
You may think using a text interpolation is the solution here, for example:
<p class="header-img" style="background-image: {{ headerUrl }}"></p>
But this is not valid Vue.js syntax. This is, instead, a job for another Vue.js feature called adirective. Let's explore directives first and then come back to solving this problem.
推薦閱讀
- JavaScript從入門到精通(微視頻精編版)
- What's New in TensorFlow 2.0
- vSphere High Performance Cookbook
- 青少年軟件編程基礎與實戰(圖形化編程三級)
- Implementing Cisco Networking Solutions
- 算法訓練營:提高篇(全彩版)
- Spring核心技術和案例實戰
- SQL Server數據庫管理與開發兵書
- 微服務架構深度解析:原理、實踐與進階
- Mastering Business Intelligence with MicroStrategy
- SwiftUI極簡開發
- Docker:容器與容器云(第2版)
- Get Your Hands Dirty on Clean Architecture
- R語言實戰(第2版)
- Flask開發Web搜索引擎入門與實戰