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

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.

主站蜘蛛池模板: 余姚市| 嘉峪关市| 称多县| 石狮市| 石城县| 都江堰市| 吕梁市| 宁城县| 平利县| 志丹县| 红原县| 莱西市| 河北区| 濮阳县| 土默特右旗| 上蔡县| 南平市| 凤山市| 青神县| 池州市| 昭通市| 韶关市| 通道| 乌拉特中旗| 新兴县| 长兴县| 乐业县| 鄂温| 宁波市| 中山市| 新竹市| 大洼县| 五莲县| 拉萨市| 克什克腾旗| 彭泽县| 界首市| 万源市| 葫芦岛市| 霍林郭勒市| 台中县|