const Component = Vue.extend({
template: `
<div id="app">
<button
v-for="n in 3"
:key="n"
:class="['btn', 'btn-default', { active: index === n }]"
@click="switchTab(n)"
>
Tab {{ n }}
</button>
<div class="alert alert-success" v-text="message"/>
</div>
`,
data() {
return {
index: 0,
message: 'Select a tab',
};
},
methods: {
switchTab(index) {
this.index = index;
this.message = 'Loading...';
this.loadContent(index)
.then(message => { this.message = message; });
},
loadContent(index) {
return new Promise((resolve) => {
setTimeout(() => resolve(`Message #${index}`), 1000);
});
},
},
});
new Vue({
el: '#app',
render(h) {
return h(Component);
}
});