Reputation: 2301
I'm trying to pass into a component, via prop, a color
attribute, which will determine the background color of the component. The choices for the color
attribute are 'red' and 'blue'.
The actual component is set up as the following:
Vue.component('greeting', {
props: ['color'],
template: '<div v-bind:class="{'add-red': color === 'red', 'add-blue': color === 'blue'}" class="box"></div>'
});
The actual color
is passed in as follows:
<component color='red' :is='currentComponent'></component>
But I can't seem to get the class binding to work in my jsfiddle.
https://jsfiddle.net/cckLd9te/3217/
Upvotes: 0
Views: 1086
Reputation: 22403
Your template is mixing between single quote '
and double quote "
. You should use escape character
Vue.component('greeting', {
props: ['color'],
template: '<div v-bind:class="{\'add-red\': color === \'red\', \'add-blue\': color === \'blue\'}" class="box"></div>'
});
Upvotes: 1