javascript - How to catch Jquery event from vue.js -


scenario: have iframe (which hosted in same domain, purely use jquery only) , coded trigger events parameters. , have catch events parameters in parent vue.js application.

iframe:

$('*').mouseover(function (event) {   var event = jquery.event( "mouseover-highlight" );   event.top = $(this).offset().top;   event.left = $(this).offset().left;   parent.$('body').trigger(event); }); 

vue.js

catch event somehow vue.js , set div's css styles accordingly (set 'absolute' position). have done using vue.js before v2 comes using jquery inside vue.js, i've seen in docs vue.js isn't able catch native events anymore. solution ?

jquery uses it's own event system. cannot catch events emitted jquery vue, have catch them jquery , call vue handler.

new vue({   el: "#app",   data:{     iframesource: $("template").html()   },   methods:{     onmouseover(event){       alert(`top: ${event.top}, left: ${event.left}`)     }   },   mounted(){     $("body").on("mouseover-highlight", this.onmouseover)       },   beforedestroy(){     $("body").off("mouseover-hightlight", this.onmouseover)   } }) 

here an example of working.

note: when adding events other vue, should manage removing them yourself, if adding in component. components created/destroyed more once , don't want end multiple handlers.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -