ant-design / ant-design-pro

👨🏻‍💻👩🏻‍💻 Use Ant Design like a Pro!
https://pro.ant.design
MIT License
36.34k stars 8.14k forks source link

🧐[问题]在什么地方注册 document.addEventListener(DOMContentLoaded, () => {})? #8094

Closed lincoln310 closed 3 years ago

lincoln310 commented 3 years ago

🧐 问题描述

基本需求是: 我需要把从网络上下载一个js文件,然后调用其函数,注册一个DOMContentLoaded的事件处理函数,需要在什么地方添加?

详细需求是: 我想用python eel和antdpro整合,一起使用。python做后台,antdpro做页面,同时支持api相互调用。 但是eel中也有一个websocket,而antdpro在npm start的时候也有一个,我没找到怎么并存。也不明白为什么antdpro为什么会有一个websocket连接。

💻 eel整合react的示例在这里:https://github.com/ChrisKnott/Eel/tree/master/examples/07%20-%20CreateReactApp

我尝试了如下方式: 1、 这用antdpro创建工程, 2、 把上面eel+react示例中的eel_CRA.py拷贝到新工程根目录下面,并做了如下修改

def start_eel(develop):
    """Start Eel with either production or development configuration."""

    if develop:
        directory = 'src/pages/app'
        app = 'App'
        page = {'port': 8000}

3、 pages目录下构建app子目录 4、 把上面示例中的src中的App.tsx和App.css放到app子目录下, 5、 在document.ejs中添加对"http://localhost:8080/eel.js"的引用(这个不能静态引用,因为python运行时,会把python的api加入,生成新的eel.js,所以这样获取的eel.js中有python的api) 6、 typings.d.ts中添加上面示例中react-app-env.d.ts中对window.eel的声明 7、 App.tsx中加入对serviceWorker.ts的引用 8、 在route.ts中加入app的路径

🚑 其他信息

运行时,需要先运行 python eel_CRA.py true,然后npm start。 但是总是提示devScript中的websocket连接失败 image 然后调用不到python的api

lincoln310 commented 3 years ago

it worked!