I'm brand new to vuejs and I'm trying to get a simple site set up with it. I have a component for each page (About us, Contact us, etc).
This is my working starting point
Vue.component('about-us', {
template: '<div>...lots of markup...</div>'
});
I want to transform that code into something that works asynchronously. Attempting to follow the docs, here is my code:
Vue.component('about-us', function(resolve, reject){
let template_string = '';
// Load the template with ajax
$.post(ajax_url, {'action': 'get_about_page'}, function(r){
r = JSON.parse(r);
// Save the template string
if( r.success ) {
template_string = r.data;
}
});
// Resolve callback for Vue
resolve({
template: template_string
});
});
The error I get is:
[Vue warn]: Failed to mount component: template or render function not defined. found in ---> Anonymous Root
Question: Is my approach wrong? Is it a syntax problem? I'm not sure if I'm on the right path. (yes I have jQuery loaded)
resolvecall in the callback:if (r.success) { resolve({ template: r.data }) }