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

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.

主站蜘蛛池模板: 洱源县| 潮州市| 秀山| 西青区| 潼南县| 南通市| 广东省| 天气| 灵璧县| 南部县| 汉阴县| 镇坪县| 金平| 阿荣旗| 宿松县| 牡丹江市| 沭阳县| 阜阳市| 隆化县| 通渭县| 信宜市| 长兴县| 密云县| 周至县| 临清市| 黄浦区| 达拉特旗| 防城港市| 浦城县| 邻水| 甘德县| 仁化县| 轮台县| 项城市| 邢台县| 昌图县| 保靖县| 青铜峡市| 建瓯市| 普宁市| 榕江县|