W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
每一個 在點擊時觸發(fā)一個事件。使用 API 來處理它們,無論是在全局的 上還是在特定的窗口上。CustomMenuItem
on_menu_event
tauri::Builder
use tauri::{CustomMenuItem, Menu, MenuItem};
fn main() {
let menu = Menu::new(); // configure the menu
tauri::Builder::default()
.menu(menu)
.on_menu_event(|event| {
match event.menu_item_id() {
"quit" => {
std::process::exit(0);
}
"close" => {
event.window().close().unwrap();
}
_ => {}
}
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
use tauri::{CustomMenuItem, Menu, MenuItem};
use tauri::{Manager, WindowBuilder};
fn main() {
let menu = Menu::new(); // configure the menu
tauri::Builder::default()
.setup(|app| {
let window = WindowBuilder::new(
app,
"main-window".to_string(),
tauri::WindowUrl::App("index.html".into()),
)
.menu(menu)
.build()?;
let window_ = window.clone();
window.on_menu_event(move |event| {
match event.menu_item_id() {
"quit" => {
std::process::exit(0);
}
"close" => {
window_.close().unwrap();
}
_ => {}
}
});
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: