当前位置: 首页 > news >正文

使用ThorUi

在这里插入图片描述
摘要: 官网

今天遇到一个老项目,使用的是ThorUi组件库!之前没有用过这组件库,所以记录一下不同框架是使用情况!

ThorUI 是一个基于 Thorium 的 UI 框架,用于构建跨平台的桌面应用程序。如果你打算使用 ThorUI 来开发你的应用,以下是一些基本的步骤和示例代码,帮助你入门。

html使用ThorUi:

ThorUI 是一个基于 Thorium 的 UI 框架,用于构建跨平台的桌面应用程序。如果你想在 HTML 中使用 ThorUI,你需要确保你的项目已经正确配置了 Thorium 和 ThorUI。

以下是一个简单的示例,展示如何在 HTML 中使用 ThorUI 来创建一个基本的窗口。

  1. 初始化项目
    首先,创建一个新的目录并初始化一个 Node.js 项目:
mkdir my-thorui-app
cd my-thorui-app
npm init -y
  1. 安装 ThorUI
    在项目目录下安装 ThorUI:
npm install thorium-ui
  1. 创建主文件
    创建一个 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();}
});
  1. 创建 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>
  1. 运行应用
    在项目目录下运行以下命令启动你的应用:
npx electron main.js

vue/uniapp使用ThorUi:
ThorUI 是一个基于 Thorium 的 UI 框架,用于构建跨平台的桌面应用程序。如果你想在 Vue.js 项目中使用 ThorUI,你需要确保你的项目已经正确配置了 Thorium 和 ThorUI。

以下是一个简单的示例,展示如何在 Vue.js 项目中使用 ThorUI 来创建一个基本的窗口。

  1. 初始化项目
    首先,创建一个新的目录并初始化一个 Node.js 项目:
mkdir my-vue-thorui-app
cd my-vue-thorui-app
npm init -y
  1. 安装依赖
    安装 Vue CLI 和其他必要的依赖:
npm install -g @vue/cli
vue create my-vue-app
cd my-vue-app
npm install thorium-ui
  1. 修改 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');
  1. 修改 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>
  1. 创建 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>
  1. 修改 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>
  1. 运行应用
    在项目目录下运行以下命令启动你的应用:
npm run serve

然后,打开另一个终端窗口,运行以下命令启动 Thorium 应用:

npx electron main.js

react使用ThorUi:

ThorUI 是一个基于 Thorium 的 UI 框架,用于构建跨平台的桌面应用程序。如果你想在 React 项目中使用
ThorUI,你需要确保你的项目已经正确配置了 Thorium 和 ThorUI。

以下是一个简单的示例,展示如何在 React 项目中使用 ThorUI 来创建一个基本的窗口。

  1. 初始化项目
    首先,创建一个新的目录并初始化一个 Node.js 项目:
mkdir my-react-thorui-app
cd my-react-thorui-app
npm init -y
  1. 安装依赖
    安装 React 和其他必要的依赖:
npx create-react-app my-react-app
cd my-react-app
npm install thorium-ui
  1. 修改 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>
  1. 修改 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;
  1. 修改 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();
  1. 运行应用
    在项目目录下运行以下命令启动你的应用:
npm start

然后,打开另一个终端窗口,运行以下命令启动 Thorium 应用:

npx electron main.js

Angular使用ThorUi:

ThorUI 是一个基于 Thorium 的 UI 框架,用于构建跨平台的桌面应用程序。如果你想在 Angular 项目中使用
ThorUI,你需要确保你的项目已经正确配置了 Thorium 和 ThorUI。

以下是一个简单的示例,展示如何在 Angular 项目中使用 ThorUI 来创建一个基本的窗口。

  1. 初始化项目
    首先,创建一个新的目录并初始化一个 Node.js 项目:
mkdir my-angular-thorui-app
cd my-angular-thorui-app
npm init -y
  1. 安装依赖
    安装 Angular CLI 和其他必要的依赖:
npm install -g @angular/cli
ng new my-angular-app
cd my-angular-app
npm install thorium-ui
  1. 修改 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>
  1. 修改 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();}});}
}
  1. 修改 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>
  1. 运行应用
    在项目目录下运行以下命令启动你的应用:
ng serve

然后,打开另一个终端窗口,运行以下命令启动 Thorium 应用:

npx electron main.js
http://www.lryc.cn/news/481156.html

相关文章:

  • 【Promise】自定义promise
  • Docker容器部署Windows系统教程
  • js id数组转字符串
  • 如何在 Android 上增加 SELinux 权限
  • MySQL:数据类型建表
  • Linux:版本控制器git的简单使用+gdb/cgdb调试器的使用
  • 【React.js】AntDesignPro左侧菜单栏栏目名称不显示的解决方案
  • 力扣力扣力:91.解码方法
  • 一些面试题总结(二)
  • Hive-testbench套件使用文档
  • 大数据新视界 -- 大数据大厂之 Impala 性能优化:新技术融合的无限可能(下)(12/30)
  • Python | Leetcode Python题解之第540题有序数组中的单一元素
  • AHB Matrix 四星级 验证笔记(2.4) Tt3.3AHB总线协议测试时的 并行数据
  • 前端零基础学习Day-Eight
  • 贪心算法day3(最长递增序列问题)
  • 【论文复现】MSA+抑郁症模型总结(三)
  • 【软件测试】敏捷模型(Scrum模型)和V模型、W模型
  • 【go从零单排】接口(interface)和多态(Polymorphism)
  • SI5319C-C-GM,SiliconLabs芯科 SI5319C-C-GMR,时钟合成器/抖动清除器 封装 QFN-36 在售 20000PCS 23+
  • 使用批处理脚本批量删除Maven无效依赖
  • 腾讯cos对象存储,下行流量费贵,是否可以加入服务器减少费用,架构如何设计
  • 【SAP】关于权限的继承
  • SpringBoot技术下的共享汽车运营平台
  • SwiftUI开发教程系列 - 第7章:数据流和状态管理
  • Ubuntu系统安装NVIDIA驱动、CUDA、PyTorch等GPU深度学习环境
  • 电子学会2024年3月青少年软件编程(图形化)等级考试试卷(三级)真题,含答案解析
  • 初学者指南:用例图——开启您的软件工程之旅
  • 二叉树遍历/算法数据结构
  • C#字符串的不可变性:内存管理与线程安全的优势分析
  • 【杂记】之语法学习第四课手写函数与结构体