首页 > 解决方案 > 如何在反应中访问cefSharp

问题描述

我正在尝试在 C# .net 应用程序中加载 react url。我想在我们的 React 应用程序中访问 c​​efSharp 对象。像这样

 useEffect(() => {
    if (typeof CefSharp !== "undefined") {
      (async function() {
        await CefSharp.BindObjectAsync("cefCustomObject");

        cefCustomObject.showDevTools();
        cefCustomObject.writetodebug("test","testestestest");
        cefCustomObject.opencmd();
      })();
    }
  }, []);

我已经看到在 vue 中使用上面的代码。我想对 react 做同样的事情。编辑:使用窗口对象。现在它为 window.cefCustomObject.showDevTools() 引发错误

 useEffect(() => {
    if (typeof window.CefSharp !== "undefined") {
      (async function() {
        await window.CefSharp.BindObjectAsync("cefCustomObject");

        window.cefCustomObject.showDevTools();
        window.cefCustomObject.writetodebug("test","testestestest");
        window.cefCustomObject.opencmd();
      })();
    }
  }, []);

标签: c#.netreactjscefsharp

解决方案


推荐阅读