React + electronjs 实现桌面软件开发引入 electronjs 及 node api
React 与 electronjs 安装及运行请百度。
electronjs中引入 React
// electronjs 目录下的 main.js,loadFile修改为 loadURL // mainWindow.loadFile(‘index.html‘) mainWindow.loadURL("http://localhost:3000/");
// electronjs 目录下的 preload.js 最底下追加 // load Api 需要什么 api 就引入什么api const loadApi = [ ‘electron‘, // 引入 electron ‘mysql‘, // 引入 mysql ]; loadApi.map((item)=>{ global[item] = require(item); });
React中调用 preload.js文件中暴露的 api
import React,{Component} from ‘react‘; import { HashRouter as Router, Link, Route } from ‘react-router-dom‘; import ‘./App.css‘; import { Button } from ‘element-react‘; const Home = () => ( <div> <h2>Home</h2> </div> ) const About = () => ( <div> <h2>About</h2> </div> ) const Product = () => ( <div> <h2>Product</h2> </div> ) // const electron = window.electron class App extends Component { Test(){ } render(){ const { electron } = window.electron; // console.log(window.electron); return ( <Router> <div className="App"> <Link to="/">Home</Link> <Link to="/About">About</Link> <Link to="/Product">Product</Link> <hr/> <Route path="/" exact component={Home}></Route> <Route path="/about" component={About}></Route> <Route path="/product" component={Product}></Route> </div> </Router> ) } } export default App;
相关推荐
游走的豚鼠君 2020-11-10
sanallen 2020-06-14
Trustport 2020-05-06
81417707 2020-10-30
ctg 2020-10-14
小飞侠V 2020-09-25
PncLogon 2020-09-24
jipengx 2020-09-10
颤抖吧腿子 2020-09-04
wwzaqw 2020-09-04
maple00 2020-09-02
青蓝 2020-08-26
罗忠浩 2020-08-16
liduote 2020-08-13
不知道该写啥QAQ 2020-08-02
pengruiyu 2020-08-01
wmd看海 2020-07-27
孝平 2020-07-18