Warning: I'm extremely new to Vue.
I'm using it to build a small form widget that can be embedded on various sites for my clients. Each of my clients can customize the form, so I'm using the vue-form-generator package to load a custom schema from my API and then generate the form.
I've gotten it to load data, but I'm not sure how to defer loading of that component until the data has finished loading. I attempted to use v-if, but the property seems to be bound to data, which is where I was doing my data loading.
<template>
<div id="app">
<vue-form-generator v-if="loaded" :schema="schema" :model="model" :options="formOptions"></vue-form-generator>
</div>
</template>
<script>
import Vue from 'vue'
import VueFormGenerator from 'vue-form-generator/dist/vfg-core.js'
import 'vue-form-generator/dist/vfg-core.css'
Vue.use(VueFormGenerator)
export default {
name: 'app',
data: function () {
return fetch('http://localhost:3000/forms')
.then(function (response) {
loaded = true;
return response.json()
}).then(function (json) {
return json
}).catch(function (ex) {
console.log('parsing failed', ex)
})
}
}
</script>
Is there a better approach here?
Thanks!