My component is simple:
<template>
<btn :color="color" @click="toggleColor">{{btnmsg}}</btn>
</template>
<script>
import { Btn } from 'chico'
export default {
name: 'AButton',
components: {
Btn
},
data() {
return {
btnmsg: 'Legia pany',
colors: [
'blue', 'black', 'green',
'orange', 'teal', 'cyan',
'yellow', 'white'
],
color: 'red'
}
},
methods: {
toggleColor() {
this.color = this.colors[Math.floor(Math.random() * Math.floor(this.colors.length))];
}
}
}
</script>
The <Btn>
from the ChicoFamily goes something like this:
<template>
<button :is="tag" :class="[className, {'active': active}]" :type="type" :role="role">
<slot></slot>
</button>
</template>
<script>
import classNames from 'classnames';
export default {
props: {
tag: {
type: String,
default: "button"
},
color: {
type: String,
default: "default"
},
//...it takes a lot of props...
},
data() {
return {
className: classNames(
this.floating ? 'btn-floating' : 'btn',
this.outline ? 'btn-outline-' + this.outline : this.flat ? 'btn-flat' : this.transparent ? '' : 'btn-' + this.color,
//...classes derived from these props...
),
};
}
}
</script>
It's a button that, when clicked, should change its color. Clicking it indeed changes the prop passed, but does not re-render the button in the new color.
Why does passing a different prop not re-render the button?
The <Btn>
takes its color from Bootstrap classes deriving from the prop. Could it be that the Btn gets the proper prop, but the className
mechanic does not catch up?