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

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.

主站蜘蛛池模板: 玉龙| 泉州市| 山阴县| 白朗县| 塔河县| 吴川市| 武胜县| 江源县| 包头市| 海兴县| 龙江县| 敦化市| 嘉峪关市| 浦城县| 铜陵市| 康保县| 阜康市| 建瓯市| 丁青县| 大同县| 大冶市| 报价| 亳州市| 玉溪市| 黄冈市| 称多县| 岳西县| 卢湾区| 枝江市| 扎赉特旗| 龙井市| 涿鹿县| 海丰县| 蓬溪县| 湘潭县| 囊谦县| 永胜县| 西乌珠穆沁旗| 嘉鱼县| 大洼县| 灵宝市|