利用ThorUi
https://i-blog.csdnimg.cn/direct/cfb8f923687146aca32c2659ef2d234e.gif#pic_center摘要: 官网
今天碰到一个老项目,利用的是ThorUi组件库!之前没有效过这组件库,所以记录一下差别框架是利用环境!
ThorUI 是一个基于 Thorium 的 UI 框架,用于构建跨平台的桌面应用程序。假如你打算利用 ThorUI 来开发你的应用,以下是一些根本的步调和示例代码,帮助你入门。
html利用ThorUi:
ThorUI 是一个基于 Thorium 的 UI 框架,用于构建跨平台的桌面应用程序。假如你想在 HTML 中利用 ThorUI,你须要确保你的项目已经精确设置了 Thorium 和 ThorUI。
以下是一个简单的示例,展示怎样在 HTML 中利用 ThorUI 来创建一个根本的窗口。
[*]初始化项目
起首,创建一个新的目次并初始化一个 Node.js 项目:
mkdir my-thorui-app
cd my-thorui-app
npm init -y
[*]安装 ThorUI
在项目目次下安装 ThorUI:
npm install thorium-ui
[*]创建主文件
创建一个 main.js 文件,这是你的应用的入口点。
const { app, BrowserWindow } = require('thorium-ui');
function createWindow() {
// 创建浏览器窗口
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
// 加载应用的 HTML 文件
win.loadFile('index.html');
}
// 当应用准备好时,创建窗口
app.whenReady().then(createWindow);
// 当所有窗口关闭时退出应用(除了 macOS)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
[*]创建 HTML 文件
创建一个 index.html 文件,作为你的应用界面。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My ThorUI App</title>
<!-- 引入 ThorUI 样式 -->
<link rel="stylesheet" href="node_modules/thorium-ui/dist/css/thorium-ui.min.css">
</head>
<body>
<div class="container">
<h1>Hello, ThorUI!</h1>
<button id="myButton" class="btn btn-primary">Click Me</button>
</div>
<!-- 引入 ThorUI JavaScript -->
<script src="node_modules/thorium-ui/dist/js/thorium-ui.min.js"></script>
<script>
// 使用 ThorUI 组件
document.getElementById('myButton').addEventListener('click', function() {
alert('Button clicked!');
});
</script>
</body>
</html>
[*]运行应用
在项目目次下运行以下下令启动你的应用:
npx electron main.js
vue/uniapp利用ThorUi:
ThorUI 是一个基于 Thorium 的 UI 框架,用于构建跨平台的桌面应用程序。假如你想在 Vue.js 项目中利用 ThorUI,你须要确保你的项目已经精确设置了 Thorium 和 ThorUI。
以下是一个简单的示例,展示怎样在 Vue.js 项目中利用 ThorUI 来创建一个根本的窗口。
[*]初始化项目
起首,创建一个新的目次并初始化一个 Node.js 项目:
mkdir my-vue-thorui-app
cd my-vue-thorui-app
npm init -y
[*]安装依赖
安装 Vue CLI 和其他须要的依赖:
npm install -g @vue/cli
vue create my-vue-app
cd my-vue-app
npm install thorium-ui
[*]修改 main.js
在 src 目次下找到 main.js 文件,并举行以下修改:
import { createApp } from 'vue';
import App from './App.vue';
import { app, BrowserWindow } from 'thorium-ui';
function createWindow() {
// 创建浏览器窗口
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
// 加载应用的 HTML 文件
win.loadURL('http://localhost:8080');
}
// 当应用准备好时,创建窗口
app.whenReady().then(createWindow);
// 当所有窗口关闭时退出应用(除了 macOS)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
createApp(App).mount('#app');
[*]修改 public/index.html
在 public 目次下找到 index.html 文件,并举行以下修改:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Vue ThorUI App</title>
<!-- 引入 ThorUI 样式 -->
<link rel="stylesheet" href="node_modules/thorium-ui/dist/css/thorium-ui.min.css">
</head>
<body>
<div id="app"></div>
<!-- 引入 ThorUI JavaScript -->
<script src="node_modules/thorium-ui/dist/js/thorium-ui.min.js"></script>
</body>
</html>
[*]创建 Vue 组件
在 src/components 目次下创建一个新的组件文件 HelloWorld.vue:
<template>
<div class="container">
<h1>Hello, ThorUI!</h1>
<button id="myButton" class="btn btn-primary">Click Me</button>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
mounted() {
document.getElementById('myButton').addEventListener('click', function() {
alert('Button clicked!');
});
}
};
</script>
<style scoped>
.container {
text-align: center;
margin-top: 50px;
}
</style>
[*]修改 App.vue
在 src 目次下找到 App.vue 文件,并举行以下修改:
<template>
<div id="app">
<HelloWorld />
</div>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue';
export default {
name: 'App',
components: {
HelloWorld,
},
};
</script>
[*]运行应用
在项目目次下运行以下下令启动你的应用:
npm run serve
然后,打开另一个终端窗口,运行以下下令启动 Thorium 应用:
npx electron main.js
react利用ThorUi:
ThorUI 是一个基于 Thorium 的 UI 框架,用于构建跨平台的桌面应用程序。假如你想在 React 项目中利用
ThorUI,你须要确保你的项目已经精确设置了 Thorium 和 ThorUI。
以下是一个简单的示例,展示怎样在 React 项目中利用 ThorUI 来创建一个根本的窗口。
[*]初始化项目
起首,创建一个新的目次并初始化一个 Node.js 项目:
mkdir my-react-thorui-app
cd my-react-thorui-app
npm init -y
[*]安装依赖
安装 React 和其他须要的依赖:
npx create-react-app my-react-app
cd my-react-app
npm install thorium-ui
[*]修改 public/index.html
在 public 目次下找到 index.html 文件,并举行以下修改:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My React ThorUI App</title>
<!-- 引入 ThorUI 样式 -->
<link rel="stylesheet" href="node_modules/thorium-ui/dist/css/thorium-ui.min.css">
</head>
<body>
<div id="root"></div>
<!-- 引入 ThorUI JavaScript -->
<script src="node_modules/thorium-ui/dist/js/thorium-ui.min.js"></script>
</body>
</html>
[*]修改 src/App.js
在 src 目次下找到 App.js 文件,并举行以下修改:
import React, { useEffect } from 'react';
import { app, BrowserWindow } from 'thorium-ui';
function App() {
useEffect(() => {
function createWindow() {
// 创建浏览器窗口
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
// 加载应用的 HTML 文件
win.loadURL('http://localhost:3000');
}
// 当应用准备好时,创建窗口
app.whenReady().then(createWindow);
// 当所有窗口关闭时退出应用(除了 macOS)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
}, []);
return (
<div className="container">
<h1>Hello, ThorUI!</h1>
<button id="myButton" className="btn btn-primary">Click Me</button>
</div>
);
}
export default App;
[*]修改 src/index.js
在 src 目次下找到 index.js 文件,并举行以下修改:
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
[*]运行应用
在项目目次下运行以下下令启动你的应用:
npm start
然后,打开另一个终端窗口,运行以下下令启动 Thorium 应用:
npx electron main.js
Angular利用ThorUi:
ThorUI 是一个基于 Thorium 的 UI 框架,用于构建跨平台的桌面应用程序。假如你想在 Angular 项目中利用
ThorUI,你须要确保你的项目已经精确设置了 Thorium 和 ThorUI。
以下是一个简单的示例,展示怎样在 Angular 项目中利用 ThorUI 来创建一个根本的窗口。
[*]初始化项目
起首,创建一个新的目次并初始化一个 Node.js 项目:
mkdir my-angular-thorui-app
cd my-angular-thorui-app
npm init -y
[*]安装依赖
安装 Angular CLI 和其他须要的依赖:
npm install -g @angular/cli
ng new my-angular-app
cd my-angular-app
npm install thorium-ui
[*]修改 src/index.html
在 src 目次下找到 index.html 文件,并举行以下修改:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Angular ThorUI App</title>
<!-- 引入 ThorUI 样式 -->
<link rel="stylesheet" href="node_modules/thorium-ui/dist/css/thorium-ui.min.css">
</head>
<body>
<app-root></app-root>
<!-- 引入 ThorUI JavaScript -->
<script src="node_modules/thorium-ui/dist/js/thorium-ui.min.js"></script>
</body>
</html>
[*]修改 src/app/app.component.ts
在 src/app 目次下找到 app.component.ts 文件,并举行以下修改:
import { Component, OnInit } from '@angular/core';
import { app, BrowserWindow } from 'thorium-ui';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'My Angular ThorUI App';
ngOnInit() {
function createWindow() {
// 创建浏览器窗口
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
// 加载应用的 HTML 文件
win.loadURL('http://localhost:4200');
}
// 当应用准备好时,创建窗口
app.whenReady().then(createWindow);
// 当所有窗口关闭时退出应用(除了 macOS)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
}
}
[*]修改 src/app/app.component.html
在 src/app 目次下找到 app.component.html 文件,并举行以下修改:
<div class="container">
<h1>{{ title }}</h1>
<button id="myButton" class="btn btn-primary">Click Me</button>
</div>
[*]运行应用
在项目目次下运行以下下令启动你的应用:
ng serve
然后,打开另一个终端窗口,运行以下下令启动 Thorium 应用:
npx electron main.js
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]