- 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.
推薦閱讀
- Python編程自學手冊
- Qt 5 and OpenCV 4 Computer Vision Projects
- Building Modern Web Applications Using Angular
- Java 9 Programming Blueprints
- Wireshark Network Security
- Building Mobile Applications Using Kendo UI Mobile and ASP.NET Web API
- 單片機應用技術
- Effective Python Penetration Testing
- 實戰Java高并發程序設計(第3版)
- iOS開發實戰:從入門到上架App Store(第2版) (移動開發叢書)
- Mastering React
- Python網絡爬蟲技術與應用
- JavaScript程序設計:基礎·PHP·XML
- WCF技術剖析(卷1)
- 計算機應用基礎案例教程(第二版)