Calling VUE function through another Iframe

Asked

Viewed 140 times

0

I made a form where an action is executed in iframe, i need somehow, this file I’m opening in iframe call my function in VUE, I’m posting my code below.

new Vue({
el:"#app",

data : {  
teste : '',
},

methods :{ 

salvar : function(){
this.$refs.form.submit();
},

retorno : function(){
alert('esse é o retorno')
}

}});

External code:

<script>
  parent.retorno();
</script>
  • 1

    Both parent page and iframe are in the same domain?

  • yes, they are in the same domain

1 answer

1


you can use postMessage, example:

iframe - > 

    function handleButtonClick(e) {
      window.parent.postMessage('iframe_message')
    }

página - >

window.addEventListener('iframe_message', function() {
  console.log("chamar função");
}, false);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.