第三方小部件未在 Nuxt 3 组件中显示。

huangapple go评论74阅读模式
英文:

Third-Party Widget is not displayed in Nuxt 3 component

问题

抱歉,我只会翻译文本内容,不会回答翻译请求以外的问题。

以下是您提供的文本内容的翻译:

嗨,各位,

我正在开发一个 Nuxt 3 应用程序,应该作为我已经存在的后端的前端。作为后端,我使用开源软件 pretix 来托管我的活动。pretix 提供了一些小部件,允许在您自己的页面中嵌入结账页面,这正是我想要的(请参阅 文档)。

我的问题是小部件在我的 Nuxt3 应用程序中未显示。我可以看到在检查器中呈现了它,但我在屏幕上看不到小部件。

我的后端和前端都托管在本地主机上。在使用普通的 index.html 文件测试小部件代码时,它可以显示。

我已在我的 nuxt.config.ts 中注册了外部的 js 和 css 文件:

app: {
    head: {
      link: [
        {rel: 'stylesheet', href: 'https://pretix.eu/demo/democon/widget/v1.css'},
      ],
      script: [
        {src: 'https://pretix.eu/widget/v1.en.js', async: true},
      ],
    }
  },

我还在配置中注册了我的自定义组件:

vue: {  
    compilerOptions: {
      isCustomElement: (tag) => {
        return tag.startsWith('pretix-')
      },
    },
  },

在我的组件中,小部件代码如下:

<pretix-widget event="http://localhost:8000/td/testevent/" skip-ssl-check></pretix-widget>
<noscript>
     <div class="pretix-widget">
          <div class="pretix-widget-info-message">
              JavaScript is disabled in your browser. To access our ticket shop without JavaScript, please
              <a target="_blank" rel="noopener" href="http://localhost:8000/td/testevent/">click here</a>.
          </div>
     </div>
</noscript>

我已尝试了启用和禁用 SSR,并且在 nuxt.config.ts 中通过 ssr: false 全局禁用了 SSR,但仍然无法看到我的小部件。

如果有人有任何想法,我会感激每一个提示!

如上所述,我已经尝试了启用和禁用 SSR。我还尝试在我的机器上只打开普通的小部件 html 文件,这样可以正常工作。它只是在 Nuxt 3 组件中未呈现。

英文:

Hej guys,

I am working on a Nuxt 3 application that should hold a frontend for my already existing backend. As a backend I use the open source software pretix to host my events. pretix offers some widgets that allow to show the checkout page embbeded into your own page which is exactly what I want (see docs).

My problem is that the widget is not shown on in my nuxt3 app. I can see that it is rendered in the DOM using the inspector but I cannot see the widget on the screen.

Both my backend and my frontend are hosted on localhost. When testing the widget code with a plain index.html file it is shown.

I have registered the external js and css files in my nuxt.config.ts:

app: {
    head: {
      link: [
        {rel: &#39;stylesheet&#39;, href: &#39;https://pretix.eu/demo/democon/widget/v1.css&#39;},
      ],
      script: [
        {src: &#39;https://pretix.eu/widget/v1.en.js&#39;, async: true},
      ],
    }
  },

I have also registered my custom Component in the config:

vue: {  
    compilerOptions: {
      isCustomElement: (tag) =&gt; {
        return tag.startsWith(&#39;pretix-&#39;)
      },
    },
  },

And in my component I have the widget code as following:

&lt;pretix-widget event=&quot;http://localhost:8000/td/testevent/&quot; skip-ssl-check&gt;&lt;/pretix-widget&gt;
&lt;noscript&gt;
     &lt;div class=&quot;pretix-widget&quot;&gt;
          &lt;div class=&quot;pretix-widget-info-message&quot;&gt;
              JavaScript is disabled in your browser. To access our ticket shop without JavaScript, please
              &lt;a target=&quot;_blank&quot; rel=&quot;noopener&quot; href=&quot;http://localhost:8000/td/testevent/&quot;&gt;click here&lt;/a&gt;.
          &lt;/div&gt;
     &lt;/div&gt;
&lt;/noscript&gt;

I have tested this with ssr which gives my a Hydration warning therefore I have disabled SSR, first using a &lt;client-only&gt; tag and then by diabling ssr globally with ssr: false, in the nuxt.config.ts.

I am using Nuxt 3 and I have tested a lot of differnt stuff but although my custom element is listed in the DOM and the script and the css as well I cannot see my widget.

If someone has an idea I am happy about every hint!

As described above I have tried with SSR enabled and also disabled. I have also tried to open just the plain widget in a html file on my machine which works fine. It is just not rendered in the Nuxt 3 component.

答案1

得分: 0

I was able to solve this by binding the external script to the DOM using Javascript.

The error seems to be with the script tag that couldn't be loaded by the widget for some reason.

I followed a strategy similar to terrymorse. See my code here:

<script setup>
    const config = useRuntimeConfig()
    let pretixScript = document.createElement('script')
    pretixScript.setAttribute('src', config.public.pretixBaseUrl + '/widget/v1.de.js')
    document.head.appendChild(pretixScript)
</script>

I also changed the <pretix-widget> tag to a <div class="pretix-widget-combat"> tag which is a pretix specific solution if problems with the custom tag occur.

英文:

I was able to solve this by binding the external script to the DOM using Javascript.

The error seems to be with the script tag that couldn't be loaded by the widget for some reason.

I followed a strategy similar to terrymorse. See my code here:

&lt;script setup&gt;
    const config = useRuntimeConfig()
    let pretixScript = document.createElement(&#39;script&#39;)
    pretixScript.setAttribute(&#39;src&#39;, config.public.pretixBaseUrl + &#39;/widget/v1.de.js&#39;)
    document.head.appendChild(pretixScript)
&lt;/script&gt;

I also changed the &lt;pretix-widget&gt; tag to a &lt;div class=&quot;pretix-widget-combat&quot;&gt; tag which is a pretix specific solution if problems with the custom tag occur.

huangapple
  • 本文由 发表于 2023年6月29日 23:37:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76582592.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定