[Vuejs]-How do I pass a variable to border style property in VueJs

6๐Ÿ‘

โœ…

if you bind your style, it expects an object.

This is an object: {}. You start with curly braces you can see it in the documentation too https://v2.vuejs.org/v2/guide/class-and-style.html

:style="{ 'border-left': '10px solid ' + colour }"

or with literals:

:style="{ 'border-left': `10px solid ${colour}` }" 

You dont need to put everything inside the HTML markup, you can also put it into the data:

data() {
   return {
      styling: {
         'border-left:': `10px solid ${this.colour}`
      }
   }
}

:style="styling"
๐Ÿ‘คbill.gates

0๐Ÿ‘

Try using string template to do such a thing.
Should look something like this.
:style = "{ `border-left: 10px solid ${colour}` }"

๐Ÿ‘คVladislavChudak

Leave a comment