[Vuejs]-Vue.js cannot add style from method

2👍

Dimension in pixels need to be in string format so the function return a valid javascript object:

return {   
    width: '180px', 
    height: '180px',
    'background-color': 'yellow',
    'background-image': `url(${this.BASE_URL}/uploads/noimg.gif)`
}
👤Psidom

2👍

can I ask why would you want to do that? As far as I know if you bind a style, just create the object in the data object and do not forget to use the style sintax adapted for javascript. (Camelcase)

data(){
    return{
        yourStyleVariable: {
            backgroundColor: 'red'
        }
    }
}

Leave a comment