- 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.
推薦閱讀
- 兩周自制腳本語言
- Cocos2d-x游戲開發:手把手教你Lua語言的編程方法
- PHP網絡編程學習筆記
- INSTANT CakePHP Starter
- BeagleBone Black Cookbook
- Unity 2018 Shaders and Effects Cookbook
- JavaScript應用開發實踐指南
- Java 從入門到項目實踐(超值版)
- Scala Functional Programming Patterns
- H5+移動營銷設計寶典
- Python編程快速上手2
- 交互設計師成長手冊:從零開始學交互
- Visual C++程序設計全程指南
- Swift 2 Design Patterns
- 少年小魚的魔法之旅:神奇的Python