繁体   English   中英

Eel.* 不是 function

[英]Eel.* is not a function

这是我第一次尝试鳗鱼。 I've got a python script with some functions and I'm trying to communicate with them using @eel.expose but it gives me a javascript error - main.html:10 Uncaught TypeError: eel.startEncryption is not a function Here's my code :

<head>
    <title>Undefined</title>
    <link rel="stylesheet" href="w3pro.css">
    <script type="text/javascript" src="/eel.js"></script>
    <script>
        function startEncryption(mode){
            massage = document.getElementById("massage").value;
            code = document.getElementById("code").value;
            string = eel.startEncryption(mode, massage, code);
            document.getElementById("result").innerHTML += string;
        }
    
    </script>
</head>
<body>
    <header class="w3-panel">
        <h1>Vigenere Encryption</h1>
    </header>
    <div class="w3-panel">
        <span>Message:<input type="text" id="massage"></span>
        <br>
        <span>Code:<input type="text" id="code"></span>
        <br>
        <span>Encrypted/Decrypted:<input type="text" id="result" readonly></span>
        <br>
        <input type="button" value="Encrypt" onclick="startEncryption(1)"> 
        <input type="button" value="Decrypt" onclick="startEncryption(2)">
        
    </div>
</body>

import eel
eel.init('C:\\Users\\Fantomas\\Documents\\Programming\\cipher\\web')
eel.start('main.html')
@eel.expose
def startEncryption(mode : int, message : string, code : string):
    if mode == 1:
        ciphertext = encryptMessage(code, message)
    elif mode == 2:
        ciphertext = decryptMessage(code, message)
    return ciphertext;

我的目录中有 eel.js 文件

将您的修改为:

import eel
eel.init('C:\\Users\\Fantomas\\Documents\\Programming\\cipher\\web')
@eel.expose
def startEncryption(mode : int, message : string, code : string):
    if mode == 1:
        ciphertext = encryptMessage(code, message)
    elif mode == 2:
        ciphertext = decryptMessage(code, message)
    return ciphertext;
eel.start('main.html')

eel.start('main.html')暴露在所有共享函数之后。

正在寻找您的意见。

祝你好运

显然,没有将 eel.start 放在代码末尾通常会导致问题,但是 eel.init 的 position 与此特定问题无关。

我只是想告诉您,有时,问题不在于您的 py 代码本身,而在于您将 eel 导入 html 代码的部分,请记住,eel.js 始终在您的 eel.init 文件夹所在的任何位置生成指定为,因此在 html 代码中导入 eel.js 时,请确保其在该特定文件夹中

例如,如果您在 py 代码中指定了文件夹web

PYTHON:

eel.init('web')

那么当你在 html 中导入 eel 时,它必须像下面这样

<script src="./eel.js"></script>

注意:这里,.html文件也在web文件夹中,所以eel.js是从同一目录导入的。

所以是的,这经常发生(至少对我来说)确保在 html 代码中导入 eel.js 时没有出错。

暂无
暂无

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

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