Created
April 26, 2022 19:58
-
-
Save GoranGozo/8b3e9b8d1bc62225d80c34511360a448 to your computer and use it in GitHub Desktop.
Load VUE app in WordPress Visual Composer editor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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