i'm playing around with vue.js and have some struggle in using v-if correctly.
i'm trying to have a conditional template rendering inside a template. in the created method, the variable isloaded
is set to true, which should lead the template to be rerendered and let the Loading Data message disappear.
However, the log indicated, the delay of 2s works, so the callback is reached, but it looks like i'm not updating the data variables correctly.
I tried already several things and now i changed true/false to be strings in order to be closer to the exampled given on the official homepage, but still no success. i hope you can help me and therefor thanks a lot in advance.
please find below the interesting codesnippets:
var step1 = Vue.component('step1', {
template: '#step1',
data: function() {
return {
accounts: [],
isloaded: 'false'
}
},
created: function() {
console.log(created);
setTimeout(function() {
console.log(times over);
this.isloaded = 'true';
this.accounts = [{
id: 1234,
name: germany
}];
}, 2000);
},
methods: {
loaded: function() {
console.log(this.isloaded === 'true');
return this.isloaded === 'true';
}
}
})
new Vue({
el: '#main'
});
<script src=https://unpkg.com/[email protected]/dist/vue.js></script>
<template id=step1>
<div class=step1>
<h1>Welcome please choose your account:</h1>
<template v-if=isloaded === 'false'>
<p>Loading Data</p>
</template>
<template v-else>
<select>
<template v-for=account in accounts>
<option :value=account.id>{{ account.name }}</option>
</template>
</select>
</template>
</div>
</template>
<div id=main>
<step1></step1>
</div>