通过 localhost 服务器而不是默认的自定义协议公开你的应用资源。
Cargo.toml
[dependencies]tauri-plugin-localhost = "2.0.0"# 或者使用 Git:tauri-plugin-localhost = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
lib.rs
fn run() { tauri::Builder::default() .plugin(tauri_plugin_localhost::Builder::new().build()) .run(tauri::generate_context!()) .expect("error while running tauri application");}
Rust 提供了 localhost 插件。
use tauri::{webview::WebviewWindowBuilder, WebviewUrl}; fn run() { let port: u16 = 9527; tauri::Builder::default() .plugin(tauri_plugin_localhost::Builder::new(port).build()) .setup(move |app| { let url = format!("http://localhost:{}", port).parse().unwrap(); WebviewWindowBuilder::new(app, "main".to_string(), WebviewUrl::External(url)) .title("Localhost Example") .build()?; Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");}
© 2024 Tauri Contributors. CC-BY / MIT