Skip to content
Advertisement

vue.js component inline style concatenation

I’m stuck with a vue.js component inline style concatenation. My code is the following:

JavaScript

I’m trying to get procolors.user.profile_background_color as inline background color. Special is that the value from procolors.user.profile_background_color has no #. So I have to add this in the template.

I tried all kinds of recommendations from the web, but none worked for me.

Any help appreciated!

Advertisement

Answer

You have several choices in how to add styling. If you use v-bind:style="...", or it shorthand :style="...", you need to pass either a valid string, valid variable or a valid object.

Currently you are trying to parse background-color: #{procolors.user.profile_background_color} as javascript, which is not going to work.

You can use a javascript template to create a string:

JavaScript

It is often more readable to refactor it to use a variable or function instead:

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