官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 张家界市| 永宁县| 措勤县| 黑河市| 运城市| 文山县| 湖南省| 额尔古纳市| 遂昌县| 宜州市| 神池县| 叙永县| 扬州市| 蓬安县| 康保县| 丹寨县| 新巴尔虎右旗| 澎湖县| 邵阳县| 西林县| 景东| 锡林郭勒盟| 松滋市| 彭州市| 东丽区| 铁力市| 望江县| 鲁山县| 兰考县| 鄂州市| 金华市| 方正县| 长岭县| 开原市| 杂多县| 神木县| 名山县| 叙永县| 盖州市| 三都| 平乡县|