Tauri + Yew 项目教程

Tauri + Yew 项目教程

tauri-yew-demoDemo project for the Tauri + Yew tutorial项目地址:https://gitcode.com/gh_mirrors/ta/tauri-yew-demo

1. 项目的目录结构及介绍

tauri-yew-demo/
├── src/
│   ├── main.rs
│   └── ...
├── src-tauri/
│   ├── Cargo.toml
│   ├── tauri.conf.json
│   └── ...
├── frontend/
│   ├── index.html
│   ├── main.rs
│   └── ...
├── .gitignore
├── README.md
└── ...
  • src/: 包含 Rust 后端代码的主要目录。
  • src-tauri/: 包含 Tauri 配置文件和相关资源。
  • frontend/: 包含 Yew 前端代码和相关资源。
  • .gitignore: 指定 Git 忽略的文件和目录。
  • README.md: 项目说明文档。

2. 项目的启动文件介绍

后端启动文件

src/main.rs 是 Rust 后端的入口文件,负责启动 Tauri 应用。

fn main() {
    tauri::Builder::default()
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

前端启动文件

frontend/main.rs 是 Yew 前端的入口文件,负责渲染前端页面。

use yew::prelude::*;

struct App;

impl Component for App {
    type Message = ();
    type Properties = ();

    fn create(_ctx: &Context<Self>) -> Self {
        Self
    }

    fn view(&self, _ctx: &Context<Self>) -> Html {
        html! {
            <div>
                <h2 class=["heading"]>{"Hello World"}</h2>
            </div>
        }
    }
}

fn main() {
    yew::start_app::<App>();
}

3. 项目的配置文件介绍

Tauri 配置文件

src-tauri/tauri.conf.json 是 Tauri 的主要配置文件,包含应用的名称、版本、窗口设置等。

{
  "build": {
    "distDir": "../dist",
    "devPath": "http://localhost:8080",
    "beforeDevCommand": "npm run serve",
    "beforeBuildCommand": "npm run build"
  },
  "tauri": {
    "bundle": {
      "active": true,
      "targets": "all",
      "identifier": "com.example.app",
      "icon": ["icon.png"],
      "resources": [],
      "externalBin": [],
      "copyright": "",
      "category": "DeveloperTool",
      "shortDescription": "",
      "longDescription": "",
      "deb": {
        "depends": []
      },
      "macOS": {
        "frameworks": [],
        "minimumSystemVersion": "",
        "exceptionDomain": "",
        "signingIdentity": null,
        "entitlements": null
      },
      "windows": {
        "certificateThumbprint": null,
        "digestAlgorithm": "sha256",
        "timestampUrl": ""
      }
    },
    "allowlist": {
      "all": true
    },
    "windows": [
      {
        "title": "Tauri App",
        "width": 800,
        "height": 600,
        "resizable": true,
        "fullscreen": false
      }
    ],
    "security": {
      "csp": "default-src 'self'"
    }
  }
}

Cargo 配置文件

src-tauri/Cargo.toml 是 Rust 项目的配置文件,包含依赖项、包信息等。

[package]
name = "tauri-yew-demo"
version = "0.1.0"
edition = "2018"

[dependencies]
tauri = { version = "1.0", features = ["api-all"] }
yew = "0.19"

以上是 tauri-yew-demo 项目的基本教程,涵盖了目录结构、启动文件

tauri-yew-demoDemo project for the Tauri + Yew tutorial项目地址:https://gitcode.com/gh_mirrors/ta/tauri-yew-demo

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

劳诺轲Ulrica

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值