In my application I have many buttons. When I press it the button I would like to load a template (that replaces the selected button):
Templates:
Vue.com
You need to bind a variable to :is
property. And change this variable on button click. Also you will need to combine it with some v-show
condition. Like so:
new Vue({
el: 'body',
data: {
currentComponent: null,
componentsArray: ['foo', 'bar']
},
components: {
'foo': {
template: 'Foo component
'
},
'bar': {
template: 'Bar component
'
}
},
methods: {
swapComponent: function(component)
{
this.currentComponent = component;
}
}
});
Here is quick example:
http://jsbin.com/miwuduliyu/edit?html,js,console,output