Skip to content
ReferenceVersion 6.0.2

RIframe ​

RIframe wraps a native iframe and Naive UI Spin. Embed pages that permit it. The embedded page's CSP, framing permissions, and same-origin policy still apply. The load event signals a frame load. Verify business content separately where needed.

Interactive example ​

View example source
tsx
import { useI18n } from '@/hooks'
import { RIframe } from '@ray-template/ui/iframe'
import { NButton, NCard, NTag } from 'naive-ui'
import DemoPage from '../components/DemoPage'

export default defineComponent({
  name: 'IframeDemo',
  setup() {
    const { t } = useI18n('demoDetails')
    const lazyMounted = ref(false)
    const loaded = reactive({ eager: false, lazy: false })
    const source = `${import.meta.env.BASE_URL}examples/embed.html`

    return () => (
      <DemoPage title={t('iframe.title')} description={t('iframe.intro')}>
        <div class="r-demo-grid">
          {(['eager', 'lazy'] as const).map((mode) => (
            <NCard key={mode} title={t(`iframe.${mode}`)}>
              {{
                'header-extra': () => (
                  <NTag
                    size="small"
                    bordered={false}
                    type={loaded[mode] ? 'success' : 'default'}
                  >
                    {loaded[mode] ? t('iframe.loaded') : t('iframe.pending')}
                  </NTag>
                ),
                default: () =>
                  mode === 'eager' || lazyMounted.value ? (
                    <RIframe
                      src={source}
                      title={t(`iframe.${mode}`)}
                      height={220}
                      lazy={mode === 'lazy'}
                      onSuccess={() => {
                        loaded[mode] = true
                      }}
                    />
                  ) : (
                    <div class="r-demo-stage">
                      <NButton
                        secondary
                        onClick={() => {
                          lazyMounted.value = true
                        }}
                      >
                        {t('iframe.mount')}
                      </NButton>
                    </div>
                  ),
              }}
            </NCard>
          ))}
        </div>
      </DemoPage>
    )
  },
})
tsx
import { RIframe } from '@/components'

export const renderReport = (url: string) => (
  <RIframe src={url} title="Inventory report" height={460} lazy="eager" />
)
PropDefaultDescription
srcRequirediframe URL. If it comes from user input, enforce application-approved origins.
width / height'100%'CSS dimensions. Percentage heights depend on the parent.
frameborder0Template border style value.
iframeWrapperClass / iframeClassNoneClasses for the wrapper and native iframe.
title / name / allowNoneNative iframe attributes. Provide title for assistive technology.
lazytruetrue or 'lazy' defers loading. false or 'eager' loads eagerly.
customSpinProps{}NSpin configuration. Internal state controls show.

onSuccess(iframe, event) and onError(event) accept a callback or array. Each src change shows the spinner until load or error. The component ref exposes the native element as iframe and its compatibility alias iframeInst, both null before mounting. Vue already unwraps them. Additional slots go to Spin, and the iframe remains the default content.

Component implementation · Props