- Full-Stack Vue.js 2 and Laravel 5
- Anthony Gore
- 127字
- 2021-07-02 19:57:20
Style binding (continued)
Coming back to our header image, we can use thev-binddirective with thestyleargumentto bind a value to thestyleattribute.
index.html:
<p class="header-img" v-bind:style="headerImageStyle"></p>
headerImageStyleis an expression that evaluates to a CSS rule that sets the background image to the correct URL. It sounds very confusing, but when you see it working, it will be quite clear.
Let's now createheaderImageStyleas a data property. When binding to a style attribute, you can use an object where the properties and values are equivalent to the CSS properties and values.
app.js:
data: { ... headerImageStyle: { 'background-image': 'url(sample/header.jpg)' } },
Save the code, refresh the page, and the header image will be shown:

Figure 2.6. Page including header image
Inspect the page with your browser Dev Tools and notice how thev-binddirective has evaluated:
<p class="header-img" style="background-image: url('sample/header.jpg');"></p>
推薦閱讀
- Java異步編程實(shí)戰(zhàn)
- Beginning Java Data Structures and Algorithms
- Oracle從新手到高手
- JIRA 7 Administration Cookbook(Second Edition)
- Java開(kāi)發(fā)入行真功夫
- Elastic Stack應(yīng)用寶典
- 概率成形編碼調(diào)制技術(shù)理論及應(yīng)用
- Spring Boot Cookbook
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)案例教程
- Clojure for Java Developers
- Learning iOS Security
- Java Web開(kāi)發(fā)基礎(chǔ)與案例教程
- ASP.NET Core 2 High Performance(Second Edition)
- Mastering R for Quantitative Finance
- Python量子計(jì)算實(shí)踐:基于Qiskit和IBM Quantum Experience平臺(tái)