简体   繁体   English

使用@JavaScript 将breadbutter.io 集成到vaadin 问题中

[英]integrate breadbutter.io into vaadin problems with @JavaScript

I'm trying to integrate the breadbutter.io js file into vaadin 21.我正在尝试将 breadbutter.io js 文件集成到 vaadin 21 中。

I suspect the problem is with vaadin rather than breadbutter.我怀疑问题出在vaadin 而不是breadbutter 上。

I've created a javascript file and stored it in我创建了一个 javascript 文件并将其存储在

frontend/js/breadbutter.js前端/js/breadbutter.js

<script>
window.initBreadButter = function() {
    BreadButter.configure({ app_id: "XXXXXXX" });
};
(function(d, s, id){ var js,fjs=d.getElementsByTagName(s)[0]; if(d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = 'https://cdn.breadbutter.io/dist/breadbutter.5.5.0.462.min.js'; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'breadbutter-js'));
</script>

On my vaadin login page I then inject the script:然后在我的 vaadin 登录页面上注入脚本:


import java.net.URISyntaxException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

import org.apache.commons.mail.EmailException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.vaadin.flow.component.Key;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.dependency.JavaScript;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.PasswordField;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.AfterNavigationEvent;
import com.vaadin.flow.router.AfterNavigationObserver;
import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterListener;
import com.vaadin.flow.router.Route;

@Access(permits = { UserRole.All })
@Route(value = "Login", layout = PublicAdminLayout.class)
@JavaScript("/js/breadbutter.js")
public class LoginView extends VerticalLayout implements PublicView, AfterNavigationObserver, BeforeEnterListener {
    public static final String NAME = "Login";
    private TextField usernameField;
    private PasswordField passwordField;

When I try to load the page I'm getting the following error:当我尝试加载页面时,出现以下错误:

Webpack Error Close
 [webpack-dev-server] Project is running at:
 [webpack-dev-server] Loopback: http://localhost:42901/
 [webpack-dev-server] On Your Network (IPv4): http://192.168.86.41:42901/
 [webpack-dev-server] Content not from webpack is served from 
'..../target/classes/META-INF/VAADIN/webapp, ..../src/main/webapp' directory

ERROR in ./js/breadbutter.js 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> 

I'm thinking that I may need to wrap the tags?我在想我可能需要包装标签?

The issue is the <script> tags in the.js file.问题是 .js 文件中的<script>标记。 A <script> should only be used in a HTML file, the JavaScript code is what's inside them. <script>只能在 HTML 文件中使用,JavaScript 代码就是其中的内容。

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

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