简体   繁体   English

渲染轻型DOM中的亮元素以与stripe.js一起使用

[英]Rendering a lit-element in light DOM to use with stripe.js

Stripe.js does not yet support shadow-dom. Stripe.js尚不支持shadow-dom。 Using Lit-elements's createRenderRoot() (documentation) , (source) you can render the template into the element's light DOM by using return this; 使用Lit-elements的createRenderRoot() (documentation)(source),您可以使用return this;将模板渲染到元素的轻型DOM中return this; . However this only works if you implement createRenderRoot() in all parent elements. 但是,仅当在所有父元素中实现createRenderRoot() ,此方法才有效。 Is there a way around this? 有没有解决的办法?

Here is my stackblitz example . 这是我的例子 It only works because I call createRenderRoot(){ return this; } 因为我调用createRenderRoot(){ return this; } createRenderRoot(){ return this; } on every element. createRenderRoot(){ return this; }每个元素上。

You are using document.getElementById(...) . 您正在使用document.getElementById(...) When using shadowRoot, you should use: 使用shadowRoot时,应使用:

this.shadowRoot.getElementById(...)

So, to mount idealBank, you could use: 因此,要安装idealBank,可以使用:

// Add an instance of the idealBank Element into the `ideal-bank-element` <div>.
const bankElement = this.shadowRoot.querySelector('#ideal-bank-element');
idealBank.mount(bankElement);

The stripe.js lib may or may not work well with shadowRoot. stripe.js库在shadowRoot上可能无法正常运行。 If the lib uses document.getElementById or some other root-document construct, it may fail. 如果该库使用document.getElementById或其他一些根文档结构,则它可能会失败。

Morbidick's stripe-elements talks directly with the Stripe token backend. Morbidick的stripe-elements直接与Stripe令牌后端对话。 It doesnt use stripe.js so it doesn't have the same Shadow DOM restrictions. 它不使用stripe.js,因此没有相同的Shadow DOM限制。 But tokens come with their own issues. 但是令牌有其自身的问题。

Bennypowers's stripe-elements offers a custom element wrapper for Stripe.js that works in shadow DOM. Bennypowers的stripe-elements为Stripe.js提供了一个自定义元素包装器,可在影子DOM中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM