W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
src-tauri/src/main.rs
文件中定義的。 要創(chuàng)建一個命令,只需添加一個函數(shù),并使用 #[tauri::command]
注釋:#[tauri::command]
fn my_custom_command() {
println!("I was invoked from JS!");
}
必須向構(gòu)建器函數(shù)提供一個命令列表,如下所示:
// Also in main.rs
fn main() {
tauri::Builder::default()
// This is where you pass in your commands
.invoke_handler(tauri::generate_handler![my_custom_command])
.run(tauri::generate_context!())
.expect("failed to run app");
}
現(xiàn)在,可以從 JS 代碼中調(diào)用這個命令:
// When using the Tauri API npm package:
import { invoke } from '@tauri-apps/api/tauri'
// When using the Tauri global script (if not using the npm package)
// Be sure to set `build.withGlobalTauri` in `tauri.conf.json` to true
const invoke = window.__TAURI__.invoke
// Invoke the command
invoke('my_custom_command')
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: