【问题标题】:I can't figure out why the onclick action doesn't work in electron我不明白为什么 onclick 动作在电子中不起作用
【发布时间】:2021-09-30 16:55:00
【问题描述】:

[电子,打字稿,反应]

目前,我正在开发电子和反应打字稿中的应用程序。 我可以在正常反应中使用 onClick,但是当我在电子中创建它时,它不起作用。 我需要用电子写一些特别的东西吗?

render.js

import React from 'react';
import ReactDOM from 'react-dom';
import {HashRouter,Link,Route,Switch} from "react-router-dom";
import Home from './Home';

const App: React.VFC = () => {

    return (
      <HashRouter>
      <div className="App">
        <div className="menu">
          <Link to="/"><button className="btn btn-primary">Home</button></Link>
          <Link to="/folder"><button className="btn btn-primary">Folders</button></Link>
        </div>
        <Switch>
          <Route exact path="/" component={Home}/>
          <Route exact path="/folder" component={Folders}/>
        </Switch>     
      </div>
      </HashRouter>    
    );
  }


  const Folders = () => {

    const clickHandler = () => {
        console.log('foo')
    }  
    return (  
      
      <div className="d-flex flex-column w-25">
          <button className="button" onClick={()=>clickHandler()}>hoge</button>
      </div>
    )
  }

ReactDOM.render(<App />, document.getElementById('root'));

感谢您的阅读。

【问题讨论】:

  • 如果可行,也试试 onClickCapture。

标签: reactjs typescript electron


【解决方案1】:

嗯。

我在 html 文件中写了&lt;!-- &lt;script src="renderer.js"&gt;&lt;/script&gt; --&gt;。 我不知道是什么原因造成的,但这似乎干扰了它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-20
    • 1970-01-01
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多