Skip to content
Advertisement

Vue dynamic background image inline component

I’m building a banner with Vue that needs to have a dynamic background, however, it doesn’t seem to be working. Not sure what I’m doing wrong. I’ve tried a few other ways and it works if I do an image tag something like

JavaScript

But obviously this needs to be an inline background image.

Code:

component

JavaScript

View

JavaScript

Advertisement

Answer

Looks like you’ve just got some syntax errors in your style attribute around string quoting. Try

JavaScript

Might be easier to create some computed properties to resolve everything though

JavaScript

and

JavaScript

Demo ~ https://codesandbox.io/s/crimson-sky-ehn9r

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement