在 Vaadin 14 中,如何将我的 Vaadin 页面嵌入到另一个网页中?

问题描述

我有一个现有的应用程序(用 WebGuiToolkit.org 编写),我正在尝试在其中嵌入 Vaadin 14 页面。
我看过几个 Vaadin 8 的指南,比如

但没有 Vaadin 14 的指南或帮助。我正在使用 Flow。 (Vaadin 10+ 的指南也会有所帮助。)

我需要什么才能将 Vaadin 集成到另一个页面?可以通过 IFRAME 来完成吗? Vaadin 也可以在没有 iframe 的同一个 HTML 页面上使用吗?

感谢您的任何提示。

解决方法

您可以通过使用 iframe 来实现,是的 - 这应该只是标准的 iframe 用法。如果您想在没有 iframe 的情况下在页面内插入 Vaadin 14 应用程序,您可以导出一个 Web 组件,这在一定程度上限制了功能 - 本质上,您需要放弃使用 @Routes(因为 Vaadin 不再控制页面的顶级导航)。这里有一个导出 Web 组件的教程:https://vaadin.com/docs/v14/flow/integrations/embedding/tutorial-webcomponent-exporter

本质上,您需要创建一个新类,该类使用您将导出的组件的通用类型扩展 WebComponentExporter,如下所示:

public class LoginFormExporter
        extends WebComponentExporter<LoginForm> { 

    public LoginFormExporter() {
        super("login-form"); // you need to call the super constructor with a tag name
    }

    @Override
    protected void configureInstance(
            WebComponent<LoginForm> webComponent,LoginForm form) {
         // add initial configuration actions here
    }

您还需要加载自定义组件的 JavaScript 文件,以及(可能的)polyfill,然后您可以使用您的 <custom-tag>(或 <login-form>,在上面的例子中) ) 在任何网页中。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...