Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt exemple #831

Closed
frederic117 opened this issue Jun 26, 2020 · 10 comments
Closed

Nuxt exemple #831

frederic117 opened this issue Jun 26, 2020 · 10 comments

Comments

@frederic117
Copy link

Hello
I would like to use iframe-resizer with nuxt to resize a cross domain iFrame
Do someone have an exemple with nuxt please?

@davidjbradshaw
Copy link
Owner

Not sure how that would differ from the VueJS example. But if it is different, I'd be happy to add it to the docs.

@vondras
Copy link
Contributor

vondras commented Jul 29, 2020

It's not significantly different. If you're looking to register the directive globally, the conventional way is to put the directive shown in the VueJS example in a file under the plugins directory:

// plugins/iframe-resize.js
import Vue from 'vue'
import iframeResize from 'iframe-resizer/js/iframeResizer'

Vue.directive('resize', {
  bind: function(el, { value = {} }) {
    el.addEventListener('load', () => iframeResize(value, el))
  }
})

then register the plugin in nuxt.config.js:

// nuxt.config.js

export default {
  plugins: [
    { src: '~/plugins/iframe-resize', mode: 'client' }
  ]
}

If you only want to use it locally, you could register it under the Vue component's directives property:

import iframeResize from 'iframe-resizer/js/iframeResizer';

export default {
  directives:  {
    resize: {
      bind (el, { value = {} }) {
        el.addEventListener('load', () => iframeResize(value, el))
      }
    }
  }
}

Check the Vue.js docs for more on custom directives. Instead of a directive, you could also make a custom component and use the component's API as a gateway to iframe-resizer's, but that's more of a general Vue.js consideration than anything specific to Nuxt.js.

@JCFerrerG JCFerrerG mentioned this issue Sep 19, 2020
Closed
@mkruip05
Copy link

I would love this as well, is there any example or solution for a Nuxt application?

@ah-lait
Copy link

ah-lait commented Jun 29, 2021

I'm having trouble wit this - I've tried implementing like suggested by @vondras. I don't get any errors besides the log from the "v-resize='{log: true}'. In the browser, nothing happens

implementation:

		<iframe
			id="iFrameResizer0"
			v-resize="{ log: true }"
			width="560"
			height="315"
			src="https://www.youtube.com/embed/VR43cu5Vvsw"
			title="YouTube video player"
			frameborder="0"
			allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
			allowfullscreen
		></iframe>

[iFrameSizer][Host page: iFrameResizer0] [init] Sending msg to iframe[iFrameResizer0] (iFrameResizer0:8:false:true:32:true:true:null:bodyOffset:null:null:0:false:parent:scroll:true) targetOrigin: https://form.jotform.com

@Archetipo95
Copy link

Any nuxt 3 examples?

@guilherme-moneri
Copy link

After a whole morning of trial and error, I used @vondras method but the real problem was that I forgot to place the iframeResizer.contentWindow.min.js file in my iFrame file script. Also I needed to host the contentWindow file (I just uploaded it to the same bucket as the file I use for the iFrame). Reading the documentation patiently would've saved me a couple hours.

JordanPisani referenced this issue in Commbocc/hc-certified-backflow-testers Mar 6, 2023
@vfcoding
Copy link

To use this package with Nuxt3, create a new plugin in your project's plugins directory. Define a new Nuxt plugin and use the Vue resize directive to add the iframeResize method.

import iframeResize from "iframe-resizer/js/iframeResizer";
import iframeResizeContentWindow from "iframe-resizer/js/iframeResizer.contentWindow.js";
// eslint-disable-next-line no-undef
export default defineNuxtPlugin((NuxtApp) => {
  NuxtApp.vueApp.use(iframeResizeContentWindow);
  NuxtApp.vueApp.directive("resize", {
    bind: function (el, { value = {} }) {
      el.addEventListener("load", () => iframeResize(value, el));
    }
  });
});

@mathieuCatapulpe
Copy link

@vfcoding I tried your code I get no errors whatsoever but nothing happens, I don't get logs in the console.
Is there anything else to do apart from setting the plugin and adding v-resize="{ log: true }" to the iframe ?

@mathieuCatapulpe
Copy link

After some digging I managed to make it work with this code

import iframeResize from "iframe-resizer/js/iframeResizer";

// eslint-disable-next-line no-undef
export default defineNuxtPlugin((NuxtApp) => {
    NuxtApp.vueApp.use(iframeResize);

    NuxtApp.vueApp.directive("resize", {
        mounted(el, binding) {
            el.addEventListener("load", () => iframeResize(binding, el));
        },
    });
});

@davidjbradshaw
Copy link
Owner

We now have a Vue package that I think should work in Nuxt

https://iframe-resizer.com/vue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants