Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GoranGozo/8b3e9b8d1bc62225d80c34511360a448 to your computer and use it in GitHub Desktop.
Save GoranGozo/8b3e9b8d1bc62225d80c34511360a448 to your computer and use it in GitHub Desktop.
Load VUE app in WordPress Visual Composer editor
/*
How to load a VUE app in Wordpress admin inside Visual Composer editor.
For example if the VUE app is rendered using a shortcode.
Visual Composer editor is inside an iframe but calls trigger 'vc_build' on the parent.
Hence the need to register an listener on the parent (main) document and from it call a script inside the iframe.
This script can be enqueued with the WP usual wp_enqueue_script() since it will be in both the parent and iframe document.
*/
jQuery(window).on('vc_build', function() {
jQuery("#vc_inline-frame")[0].contentWindow.mountVueApp();
});
// This script is to run inside the iframe
window.mountVueApp = function(args) {
app.mount('#my-vue-app');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment