async component loading
by SUNG BIN CHO
HTML
<div id="app">
<span v-if="loading">loading...</span>
<xuande-period-vase></xuande-period-vase>
</div>
JavaScript
Vue.component('XuandePeriodVase', (resolve, reject) => {
setTimeout(()=> {
if((new Date()).getDay() !== 6){
resolve({
template: '<div> Buy for only 400000</div>',
mounted() {
this.$parent.$emit('loaded')
}
})
} else {
reject("Today is Sunday, Internet is closed!")
}
}, 1000)
})
new Vue({
el:'#app',
data: {
loading: true
},
created() {
this.$on('loaded', () => {
this.loading = false
})
}
})