25.06.2018 Views

Full-Stack Vue.js 2 and Laravel 5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Style binding (continued)<br />

Coming back to our header image, we can use the v-bind directive with the style<br />

argument to bind a value to the style attribute.<br />

index.html: <br />

headerImageStyle is an expression that evaluates to a CSS rule that sets the<br />

background image to the correct URL. It sounds very confusing, but when you<br />

see it working, it will be quite clear.<br />

Let's now create headerImageStyle as a data property. When binding to a style<br />

attribute, you can use an object where the properties <strong>and</strong> values are equivalent to<br />

the CSS properties <strong>and</strong> values.<br />

app.<strong>js</strong>: data: { ... headerImageStyle: { 'background-image':<br />

'url(sample/header.jpg)' } },<br />

Save the code, refresh the page, <strong>and</strong> the header image will be shown:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!