I'm currently diving into Vue.js 2 and I have a goal of crafting a unique custom component in the form of
<bs-container fluid="true"></bs-container>
. My intention is for Vue.component() to seamlessly handle the bootstrap 3 container classes based on the boolean value passed in the fluid
prop. This way, the code will appear much cleaner with <bs-container fluid="true"></bs-container>
rather than div class="container-fluid></div>
. Although I've made an attempt, it seems not to be functioning as expected:
HTML:
<div id="app" >
<bs-container fluid="false">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</bs-container>
JS:
Vue.component('bs-container',{
props: ['fluid'],
template: '<div :class="setClass"><slot></slot></div>',
computed: {
setClass: function() {
console.log('setClass has been called');
if (this.fluid == true) {
return 'container-fluid';
} else{
return 'container';
}
}
}
});
new Vue({
el: '#app'
});
The setClass method does not seem to be triggered. What might I be overlooking?